我有一个ArrayCollection数据提供者的列表。在我的程序中,有一个按钮,用户可以单击以执行List的selectedIndex函数,但是会先显示一个Alert,询问他们是否确定要执行此操作。用户应答警报后,将对列表的selectedIndex执行操作。selectedindex in Alert after Alert
我的问题是,在Alert窗口CloseEvent之后selectedIndex = -1,即使它被明确选中。我通过在Alert CloseEvent的代码列表中执行validateNow()来解决这个问题。
我的问题:为什么我必须这样做,我做错了什么?或者这是正常的/最佳做法?另外,有没有更好的/最好的做法来检查列表,看看除了使用try-catch之外是否还有其他选择。如果没有选择任何内容,我不希望最终用户看到生成的错误。
代码:
//Note: "fl" is a class with "friendsList" bindable ArrayCollection; for the sake of keeping this short I will not include it
private function _removeFriendClick(event:MouseEvent):void
{
try {
if (this.friendsList.selectedIndex != -1) {
Alert.show("Are you sure you want to remove "+this.fl.friendsList[this.friendsList.selectedIndex].label+" as a friend?", "Remove Friend", Alert.YES | Alert.CANCEL, this, this._removeFriendConfirm, null, Alert.CANCEL);
}
} catch (e:Error) { }
}
private function _removeFriendConfirm(event:CloseEvent):void
{
this.friendsList.validateNow();
trace(this.friendsList.selectedIndex);
}
因此,与上面的代码,如果你拿出validateNow(),抛出一个异常,因为它认为将selectedIndex为-1。
这不是正常行为,但是您显示的代码不足以评估正在发生的事情。你将不得不再给我们一些工作。 – RIAstar
为什么您不想在警报窗口之前保存选定的索引? – Anton
@RIAstar我不太清楚还有什么可以包含的? – Lyynk424