Flex - 将数据传递到选项卡式视图中

发布于 2024-11-01 19:09:43 字数 246 浏览 6 评论 0原文

我有一个有 4 个视图的项目,我将 tabBar 与 viewStack/NavigatorContent 一起使用。我设置了几个 HTTPServices 来收集 XML 并转换为可绑定的 ArrayCollections。何时以及如何将数据传递到图表、数据网格等只有用户单击选项卡才能看到的内容的最佳方式?现在我已经为每个项目设置了 createComplete 函数,然后传递它。虽然它似乎有效,但这是最好的方法,还是有更好、甚至更快的方法?

谢谢, 标记

I have a project that has 4 views where I'm using the tabBar with viewStack/NavigatorContent. I have a couple HTTPServices set up gathering the XML and converting to Bindable ArrayCollections. When and how is the best way to pass that data to such things as charts, dataGrids, etc. that aren't seen until the user clicks a tab? Right now I have each item set up with creationComplete functions that pass it then. Although it seems to be working, is this the best way, or is there something better and maybe even quicker?

Thanks,
Mark

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

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

发布评论

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

评论(2

╭ゆ眷念 2024-11-08 19:09:43

最好的方法是使用数据绑定。假设您有一个主容器,其中包含代表选项卡内容的 ViewStack 组件。因此,您应该在主容器中为数据设置 [Bindable] 属性,如下所示:

[Bindable]
private var chartData:ArrayCollection;

[Bindable]
private var dataGridData:ArrayCollection;

等等。

因此,对于包含图表的组件,您应该使用数据绑定填充图表数据:

<ViewStack>
    …
    <MyChartsTab chartData="{chartData}" />
    …
</ViewStack>

当然,您应该引入MyChartsTab 组件中的相同 chartData 字段(确保它是 public)。您的图表也可以填充数据绑定。

因此,在获取数据后,您只需填写主组件中的字段,数据绑定将执行其余工作,而无需关心您这边的初始化。

The best way is using data binding. Say you have a main container which contains ViewStack witch components representing tabs content. So you should have [Bindable] properties for data in a main container like the following:

[Bindable]
private var chartData:ArrayCollection;

[Bindable]
private var dataGridData:ArrayCollection;

etc.

So for the component, containing chart, you should populate chart data with data binding:

<ViewStack>
    …
    <MyChartsTab chartData="{chartData}" />
    …
</ViewStack>

And of course you should introduce the same chartData field (make sure it is public) in your MyChartsTab component. Your charts there can be populated with data binding too.

So after getting data you just fill your fields in main component and data binding performs the rest job without any care of initialization from your side.

绅士风度i 2024-11-08 19:09:43

创建视图时,请确保允许使用公共变量(例如“dataProvider”),您可以在其中绑定所需的数据。像这样:

<mx:ViewStack>
        <s:NavigatorContent>
            <SomeComponent dataProvider="{someData}" />
        </s:NavigatorContent>
        <s:NavigatorContent>
            <SomeComponent2 dataProvider="{someData}" />
        </s:NavigatorContent>
    </mx:ViewStack>

在自定义组件中,您将拥有:

private var _data:Object; // use strong typing if possible

public function set dataProvider(value:Object):void // use strong typing if possible
{
    this._data = value;
}

public function get dataProvider():Object
{
   return this._data;
}

When creating your views, make sure you allow a public variable (like 'dataProvider') where you can bind the data it needs. Like this:

<mx:ViewStack>
        <s:NavigatorContent>
            <SomeComponent dataProvider="{someData}" />
        </s:NavigatorContent>
        <s:NavigatorContent>
            <SomeComponent2 dataProvider="{someData}" />
        </s:NavigatorContent>
    </mx:ViewStack>

And within the custom component you'd have:

private var _data:Object; // use strong typing if possible

public function set dataProvider(value:Object):void // use strong typing if possible
{
    this._data = value;
}

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