0

我有一个显示在我的应用程序主屏幕上的 ArrayCollection。我以前有我的代码在选定的索引上推送视图。现在我已经为这个数组集合实现了我的搜索栏。所选索引与搜索索引不匹配。前任。selected index == 0 曾经是 A1c 计算器,如果有人搜索 BMI 计算器,它就会变成 A1c,因为它现在在 selected index == 0 中。

我如何通过在选择 A1c 时总是拉 A1c 来解决这个问题,依此类推,无论它是什么索引。这是代码。

            '<?xml version="1.0" encoding="utf-8"?>
            <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
                    xmlns:s="library://ns.adobe.com/flex/spark" title="iCalculate">


                <fx:Declarations>
                    <!-- Place non-visual elements (e.g., services, value objects) here -->
                </fx:Declarations>

                <s:layout>  
                    <s:VerticalLayout paddingTop="10"/>
                </s:layout>
                <fx:Script>
                    <![CDATA[
                        import mx.collections.ArrayCollection;
                        import mx.collections.ArrayList;
                        import mx.events.IndexChangedEvent;
                        import mx.utils.object_proxy;

                        import spark.collections.Sort;
                        import spark.collections.SortField;
                        import spark.components.Image;
                        import spark.components.ViewMenu;
                        import spark.events.IndexChangeEvent;



                        // This method contains the selection assignments for the                                Calculator Views
                        protected function calcList_changeHandler(event:IndexChangeEvent):void
                        {

                            if (calcList.selectedIndex == 0)//A1c Calculator
                            {
                                navigator.pushView(views.A1CCalculator);
                            }
                            else if (calcList.selectedIndex ==1)//BMI Calculator
                            {
                                navigator.pushView(views.BMI_Calculator);
                            }
                            else if (calcList.selectedIndex ==2)//GPA Calculator
                            {
                                navigator.pushView(views.GPA_Calculator);
                            }
                            else if (calcList.selectedIndex ==3)//TIP Calculator
                            {
                                navigator.pushView(views.TipCalculator);
                            }

                        }


                    //Below This Line is the code for the Filter Feature
                    private function filterList():void{
                        calcListCollection.filterFunction=searchList;
                        calcListCollection.refresh();

                    }
                    private function searchList(item:Object):Boolean{
                        var isMatch:Boolean = false
                            if(item.name.toLowerCase().search(search.text.toLowerCase())!=-1){
                                isMatch = true
                            }
                            return isMatch;
                    }
                    private function clearSearch():void{
                        calcListCollection.filterFunction=null;
                        calcListCollection.refresh();
                        search.text=""; 

                    }




                    ]]>
                </fx:Script>
                <s:HGroup width="100%" height="43">
                    <s:TextInput id="search" width="100%" prompt="Search iCalculate" textAlign="center" change="filterList()"/>

                </s:HGroup>

                <s:List id="calcList" alternatingItemColors="[#e5e4e4,#ffffff]"
                        width="100%"
                        height="98%"
                        labelField="name"
                        change="calcList_changeHandler(event)">
                    <s:dataProvider>

                        <s:ArrayCollection id="calcListCollection">  
                            <fx:Object name="A1c Calculator" />
                            <fx:Object name="BMI Calculator" />
                            <fx:Object name="GPA Calculator" />
                            <fx:Object name="Tip Calculator" />

                        </s:ArrayCollection>
                    </s:dataProvider>
                </s:List>

                <s:Label width="100%" click="navigator.pushView(views.CompanyDetail)" color="#1021C7"

'

先感谢您。

瑞安

4

1 回答 1

1

我认为原因是:您不能使用 selectedIndex 来识别视图。

因此,您可以向 ArrayList 的对象添加“viewId”属性:

<fx:Object viewId="A1c" name="A1c Calculator"/>

并且您的列表更改事件处理程序可以使用“viewId”来识别视图:

 if (calcList.selectedItem.viewId == "A1c")//A1c Calculator
 {
   navigator.pushView(views.A1CCalculator);
 }
于 2012-10-22T03:22:09.490 回答