我有一个组合框,可以作为搜索应用程序的自动提示。搜索按钮会触发搜索功能。我还想在组合框中的项目被双击或单击时触发搜索功能。代码:
//for triggering search function from combobox(search_complex) it will be
something like that but i am not sure
search_complex.addEventListener(Event.CHANGE, search);
search(event:Event):void{//something will come hereto use "selctedItem" to
trigger search function}
//search function which is working fine by pressing search button
bt_search.addEventListener(MouseEvent.CLICK, search);
function search(MouseEvent):void{
currentUserbase = [];
for (var n:int = 0; n<allUserbase.length; n++)
{
for (var k:int = 0; k<allUserbase[n].complex.length; k++)
{
if ((allUserbase[n].complex[k].value.toLowerCase() ==
search_complex.text.toLowerCase() || search_complex.text==""))
{
currentUserbase.push(allUserbase[n]);
}
}
}
updateList();
}//end search
答案 0 :(得分:1)
我不明白你到底想要什么。
你是否有搜索功能,这将是正常的。 现在你不需要每个事件的单独处理程序。所有活动都可以使用一个。由于函数参数使用“事件”类型,因为所有其他事件都继承自此基类。
检查我的代码。 cd是我的组合框。此示例使用flex3
编写<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable] private var arr:ArrayCollection = new ArrayCollection([
{name:"Alexander"},
{name:"Bernd"},
{name:"Carl"}
]);
private function init():void
{
cb.addEventListener(MouseEvent.CLICK,search);
cb.addEventListener(MouseEvent.DOUBLE_CLICK,search);
cb.addEventListener(Event.CHANGE,search);
}
private function search (event:Event) :void
{
trace (event.type);
}
]]>
</mx:Script>
答案 1 :(得分:0)
我相信你走的正确。尝试:
search_complex.addEventListener(Event.CHANGE, search);
bt_search.addEventListener(MouseEvent.CLICK, search);
function search(event:Event):void
{
currentUserbase = [];
for (var n:int = 0; n<allUserbase.length; n++)
{
for (var k:int = 0; k<allUserbase[n].complex.length; k++)
{
if ((allUserbase[n].complex[k].value.toLowerCase() == search_complex.text.toLowerCase() || search_complex.text==""))
{
currentUserbase.push(allUserbase[n]);
}
}
}
updateList();
}//end search
您应该可以使用search_complex.selectedItem.label
或search_complex.selectedItem.label
在组合框中获取所选项目,具体取决于您需要使用的属性。