如何在 Flex 4 中提供 Spark 列表中项目的链接?

发布于 2024-10-20 12:36:01 字数 1169 浏览 3 评论 0原文

<s:List id="lst"
            labelField="@label"
            change="lst_changeHandler(event)"
            horizontalCenter="0" verticalCenter="0">
        <s:dataProvider>
            <s:XMLListCollection>
                <fx:XMLList xmlns="">
                    <node label="One" />
                    <node label="Two" />
                    <node label="Three" />
                    <node label="Four" />
                    <node label="Five" />
                    <node label="Six" />
                    <node label="Seven" />
                    <node label="Eight" />
                    <node label="Nine" />
                </fx:XMLList>
            </s:XMLListCollection>
        </s:dataProvider>
    </s:List>

protected function lst_changeHandler(event:IndexChangeEvent):void
            {
               Alert.show(event.target.selectedItem); 

        }

我想用超链接扩展列表。例如,在每个节点中我也应该有一个 href 属性。然后我需要将用户重定向到所选项目。我知道 Flash 有 URLRequest 类。

我现在遇到的小问题是获取所选项目。这可能是因为 dataprovider 是 xml 而我没有进行正确的转换。或者也许比我更开明的人可以帮助我。

<s:List id="lst"
            labelField="@label"
            change="lst_changeHandler(event)"
            horizontalCenter="0" verticalCenter="0">
        <s:dataProvider>
            <s:XMLListCollection>
                <fx:XMLList xmlns="">
                    <node label="One" />
                    <node label="Two" />
                    <node label="Three" />
                    <node label="Four" />
                    <node label="Five" />
                    <node label="Six" />
                    <node label="Seven" />
                    <node label="Eight" />
                    <node label="Nine" />
                </fx:XMLList>
            </s:XMLListCollection>
        </s:dataProvider>
    </s:List>

protected function lst_changeHandler(event:IndexChangeEvent):void
            {
               Alert.show(event.target.selectedItem); 

        }

I want to extend the list with hyperlinks. For example in every node I should have an href attribute also. Then I need to redirect users to the selected item. I know Flash has the URLRequest class.

The little problem I have now is to get the selected item. It propably is because of the dataprovider is xml and I haven't done the correct casting. Or maybe some more enlightened than me can help me.

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

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

发布评论

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

评论(2

假扮的天使 2024-10-27 12:36:01
<fx:Script>
    <![CDATA[
        import flash.net.navigateToURL;

        import spark.events.IndexChangeEvent;

        protected function lst_changeHandler(event:IndexChangeEvent):void
        {
            navigateToURL(new URLRequest(lst.selectedItem.@url));
        }

    ]]>
</fx:Script>

<s:List id="lst"
        labelField="@label"
        change="lst_changeHandler(event)"
        horizontalCenter="0" verticalCenter="0"
        >
    <s:dataProvider>
        <s:XMLListCollection>
            <fx:XMLList xmlns="">
                <node label="One" url="www.internet.com" />
                <node label="Two" url="www.internet2.com" />
                <node label="Three" url="www.internet3.com" />
                <node label="Four" url="www.bla.com" />
            </fx:XMLList>
        </s:XMLListCollection>
    </s:dataProvider>
</s:List>
<fx:Script>
    <![CDATA[
        import flash.net.navigateToURL;

        import spark.events.IndexChangeEvent;

        protected function lst_changeHandler(event:IndexChangeEvent):void
        {
            navigateToURL(new URLRequest(lst.selectedItem.@url));
        }

    ]]>
</fx:Script>

<s:List id="lst"
        labelField="@label"
        change="lst_changeHandler(event)"
        horizontalCenter="0" verticalCenter="0"
        >
    <s:dataProvider>
        <s:XMLListCollection>
            <fx:XMLList xmlns="">
                <node label="One" url="www.internet.com" />
                <node label="Two" url="www.internet2.com" />
                <node label="Three" url="www.internet3.com" />
                <node label="Four" url="www.bla.com" />
            </fx:XMLList>
        </s:XMLListCollection>
    </s:dataProvider>
</s:List>
小…楫夜泊 2024-10-27 12:36:01
 var item:XML = event.target.selectedItem as XML; 
                   var label:String = item.@label; 
                   var url:String = item.@url; 
                   if(url != null) {
                    var ur:URLRequest = new URLRequest(url); 
                    navigateToURL(ur); 
                   }

真的很简单!

 var item:XML = event.target.selectedItem as XML; 
                   var label:String = item.@label; 
                   var url:String = item.@url; 
                   if(url != null) {
                    var ur:URLRequest = new URLRequest(url); 
                    navigateToURL(ur); 
                   }

It was really real simple!

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