0

アプリのメイン画面に表示される ArrayCollection があります。以前は、選択したインデックスにビューをプッシュするコードがありました。これで、この配列コレクションの検索バーを実装できました。選択したインデックスが検索インデックスと一致しません。元。選択されたインデックス == 0 は以前は A1c 電卓でしたが、誰かが BMI 電卓を検索すると、現在は選択されたインデックス == 0 にあるため、A1c になります。

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 に答える