ItemRenderer 内的导航

发布于 2024-11-06 15:31:47 字数 751 浏览 1 评论 0原文

我们如何在 itemRenderer 中导航?

例如,在Views中我们使用View.navigator(ViewNavigator)来推送和弹出视图,而ItemRenderer中没有这样的功能。

在视图中导航(简单)

<s:View>
<s:HGroup >
    <s:Button label="Questionnaire" click="navigator.pushView(view.QuestionnaireCategory1View)"/>
</s:HGroup>

在项目渲染器中导航(不可能?)

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                autoDrawBackground="true" height="56">
    <s:HGroup>
        <s:Button text="Button" click="?????????"/>
    </s:HGroup>


</s:ItemRenderer>

How can we navigate within an itemRenderer?

For example, in Views we use the View.navigator (ViewNavigator) to push and pop views, there is no such feature in ItemRenderer.

Navigation within a View (Easy)

<s:View>
<s:HGroup >
    <s:Button label="Questionnaire" click="navigator.pushView(view.QuestionnaireCategory1View)"/>
</s:HGroup>

Navigation within a Item Renderer (Impossible?)

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                autoDrawBackground="true" height="56">
    <s:HGroup>
        <s:Button text="Button" click="?????????"/>
    </s:HGroup>


</s:ItemRenderer>

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

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

发布评论

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

评论(2

素罗衫 2024-11-13 15:31:47

您希望使用冒泡事件来捕获用户与项目渲染器交互的时间。

<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark">
    <s:HGroup>
        <s:Button text="Button" click="dispatchEvent(new Event('buttonClicked', true));"/>
    </s:HGroup>
</s:ItemRenderer>

然后,当对使用项目渲染器的任何内容执行此操作时:

<DataGroup id="group" itemRenderer="YourItemRenderer" dataProvider="{someData}" creationComplete="group.addEventListener('buttonClick', someHandlerFunction);" />

然后在处理程序函数中,执行您想做的任何操作。在本例中,我在 DataGroup 创建完成时添加事件侦听器,但您可以将其添加到主容器的创建完成事件中。通过这种方式,您可以使项目渲染器保持解耦和可重用,并使用正确的软件实践(数据输入,事件输出)。

You want to use bubbling events to catch when the user interacts with an item renderer.

<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark">
    <s:HGroup>
        <s:Button text="Button" click="dispatchEvent(new Event('buttonClicked', true));"/>
    </s:HGroup>
</s:ItemRenderer>

Then when do this with whatever is using your item renderer:

<DataGroup id="group" itemRenderer="YourItemRenderer" dataProvider="{someData}" creationComplete="group.addEventListener('buttonClick', someHandlerFunction);" />

And then within your handler function, do whatever action you wanted to do. In this case, I'm adding the event listener on creation complete of the DataGroup, but you can add it to the creation complete event of the main container. This way you keep your item renderer decoupled and reusable, as well as using proper software practices (data in, events out).

心房敞 2024-11-13 15:31:47

当您创建 itemRenderer 时

<comp:MyItemRenderer navigator="{navigator}"/>

在您的 itemRenderer 中(此处称为 MyItemRenderer)

<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                autoDrawBackground="true" height="56">
<fx:Script>
    <![CDATA[
        import spark.components.ViewNavigator;

        private var _navigator:ViewNavigator;

        public function set navigator(value:ViewNavigator):void
        {
            _navigator = value;
        }
    ]]>
</fx:Script>

<s:HGroup>
    <s:Button label="Button" click="{_navigator.pushView(view.QuestionnaireCategory1View)}"/>
</s:HGroup>

In when you create your itemRenderer

<comp:MyItemRenderer navigator="{navigator}"/>

In your itemRenderer (here call MyItemRenderer)

<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                autoDrawBackground="true" height="56">
<fx:Script>
    <![CDATA[
        import spark.components.ViewNavigator;

        private var _navigator:ViewNavigator;

        public function set navigator(value:ViewNavigator):void
        {
            _navigator = value;
        }
    ]]>
</fx:Script>

<s:HGroup>
    <s:Button label="Button" click="{_navigator.pushView(view.QuestionnaireCategory1View)}"/>
</s:HGroup>

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