簡體   English   中英

如何將視圖返回到選定的索引。 flex(Flash Builder)

[英]How to return a view to a selected index. flex (flash builder )

我有一個ArrayCollection出現在我的應用程序的主屏幕上。 以前,我有我的代碼可將視圖推入選定的索引。 現在,我已經為該數組集合實現了搜索欄。 所選索引與搜索索引不匹配。 例如 選定索引== 0曾經是A1c計算器,如果有人搜索BMI計算器,則它成為A1c,因為它現在位於選定索引== 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"

'

先感謝您。

瑞安

我認為原因是:您不能使用selectedIndex來標識視圖。

因此,您可以將“ viewId”屬性添加到ArrayList的Object中:

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

並且您的列表更改事件處理程序可以使用“ viewId”來標識視圖:

 if (calcList.selectedItem.viewId == "A1c")//A1c Calculator
 {
   navigator.pushView(views.A1CCalculator);
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM