如何在 Spark 列表控件中导航?

发布于 2024-12-01 00:29:39 字数 536 浏览 1 评论 0原文

我正在使用 Spark 列表控件构建一个移动应用程序。当用户点击列表项时,我希望它导航到该通信

<s:List id="list" width="100%" height="100%" labelField=" label">
<s:dataProvider>
<s:ArrayList>
<fx:Object label="Page One" />
<fx:Object label="Page Two" />
<fx:Object label="Page Three" />
<fx:Object label="Page Four" />
</s:ArrayList>
</s:dataProvider>
</s:List>

页面

  我如何编码,以便当用户点击项目标签=“第一页”时,它将导航到 PageOneView.mxml,如果点击“第二页”,它将转到 PageTwoView.mxml 等等。   谢谢

I'm building a mobile app, using spark list control. When user tap on a list item, i want it to navigate to that correspondence page

<s:List id="list" width="100%" height="100%" labelField=" label">
<s:dataProvider>
<s:ArrayList>
<fx:Object label="Page One" />
<fx:Object label="Page Two" />
<fx:Object label="Page Three" />
<fx:Object label="Page Four" />
</s:ArrayList>
</s:dataProvider>
</s:List>

how do i code it so that when user tap on item label="Page One" it will navigate to PageOneView.mxml and if it tap on "Page Two" it will go to PageTwoView.mxml and so on.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雪化雨蝶 2024-12-08 00:29:39

该列表应该调度一个更改事件。在该更改事件处理程序中,您可以将新视图推送到视图堆栈上:

if(list.selectedIndex == 0){
 navigator.pushView(viewOne);
} else if (list.selectedIndex == 1){
 navigator.pushView(viewtwo);
} else if 
etc...

The List should dispatch a change event. In that change event handler you can push the new view onto the view stack:

if(list.selectedIndex == 0){
 navigator.pushView(viewOne);
} else if (list.selectedIndex == 1){
 navigator.pushView(viewtwo);
} else if 
etc...
心房敞 2024-12-08 00:29:39

我喜欢这里的 switch 语句,因为您可以默认为一个操作,

<?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="HomeView">
    <fx:Script>
        <![CDATA[
            import spark.events.IndexChangeEvent;

            protected function list_changeHandler(event:IndexChangeEvent):void
            {
                switch(list.selectedItem.label)
                {
                    case "Page One":
                    {
                        navigator.pushView(pageOne);
                        break;
                    }
                    case "Page Two":
                    {
                        navigator.pushView(pageTwo);
                        break;
                    }                   
                    case "Page Three":
                    {
                        navigator.pushView(pageThree);
                        break;
                    }                   
                    case "Page Four":
                    {
                        navigator.pushView(pageFour);
                        break;
                    }                       
                    default:
                    {
                        navigator.pushView(pageOne);
                        break;
                    }
                }
            }

        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:List id="list" width="100%" height="100%" change="list_changeHandler(event)"
            labelField="label">
        <s:dataProvider>
            <s:ArrayList>
                <fx:Object label="Page One"/>
                <fx:Object label="Page Two"/>
                <fx:Object label="Page Three"/>
                <fx:Object label="Page Four"/>
            </s:ArrayList>
        </s:dataProvider>
    </s:List>
</s:View>

只是一种不同的方式,适合我的逻辑,在 Flash Builder 4.6 中创建。

杰克

I like the switch statement here as you can default to an action,

<?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="HomeView">
    <fx:Script>
        <![CDATA[
            import spark.events.IndexChangeEvent;

            protected function list_changeHandler(event:IndexChangeEvent):void
            {
                switch(list.selectedItem.label)
                {
                    case "Page One":
                    {
                        navigator.pushView(pageOne);
                        break;
                    }
                    case "Page Two":
                    {
                        navigator.pushView(pageTwo);
                        break;
                    }                   
                    case "Page Three":
                    {
                        navigator.pushView(pageThree);
                        break;
                    }                   
                    case "Page Four":
                    {
                        navigator.pushView(pageFour);
                        break;
                    }                       
                    default:
                    {
                        navigator.pushView(pageOne);
                        break;
                    }
                }
            }

        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:List id="list" width="100%" height="100%" change="list_changeHandler(event)"
            labelField="label">
        <s:dataProvider>
            <s:ArrayList>
                <fx:Object label="Page One"/>
                <fx:Object label="Page Two"/>
                <fx:Object label="Page Three"/>
                <fx:Object label="Page Four"/>
            </s:ArrayList>
        </s:dataProvider>
    </s:List>
</s:View>

Just a different way, suits my logic, created in Flash Builder 4.6.

Jacko

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文