我试图根据文本框中的值过滤组合框数据提供者。当dataprovider的内容更改时,Combo框会自动调用change事件方法。请在下面找到示例代码。
过滤器效用函数:
private function filterLocations(event:FocusEvent):void {
locationsList1.filterFunction = filterUtility;
locationsList1.refresh();
}
public function filterUtility(item:Object):Boolean {
// pass back whether the location square foot is with in the range specified
if((item.SQUARE_FOOTAGE >= rangeText1.text) && (item.SQUARE_FOOTAGE rangeText2.text))
return item.SQUARE_FOOTAGE;
}
// THIS WOULD BE CALLED WHEN COMBO BOX SELECTION IS DONE
private function selectLocationsReports(event:ListEvent):void {
selectedItem =(event.currentTarget as ComboBox).selectedItem.LOCATION_ID;
}
当DataProvider刷新时,它会自动调用change方法并抛出Null Pointer函数,因为它过早地调用了上面的selectLocationsReports方法及其抛出错误。
有人可以告诉我如何在刷新dataprovider时停止传播的CHANGE事件。
答案 0 :(得分:0)
您无法停止CHANGE事件,只是不要添加事件侦听器,除非您准备好接收事件。我没有看到Event.CHANGE的事件监听器在上面的代码中。
在ComboBox准备就绪之前,请确保不addEventListener(Event.CHANGE, selectLocationsReports)
。
答案 1 :(得分:0)
要做的另一件事(在Kekoa的响应之上)在事件处理程序中放置一个if语句,并在开始使用它之前检查以确保数据存在。
答案 2 :(得分:0)
我经常使用的一种方便的语法是
if(dataprovidername){
}