何时(从生命周期角度)为 Flex 3 上的 LIST 容器设置数据提供者是正确的时间点

发布于 2024-08-21 01:51:27 字数 633 浏览 1 评论 0原文

我正在使用自己的项目渲染器创建一个 LIST 容器来显示 xml 文件。

现在,我正在重写项目渲染器中的 public override function set data(value:Object):void 方法,问题是该函数被调用了很多次(!!)(比数据提供者长度)。

也许我没有正确设置数据提供程序,这是我的做法:

首先声明可绑定属性:

[Bindable]
private var _listDataProvider:XMLListCollection;

然后,创建 LIST 对象:

<mx:List id="list" dataProvider="{_listDataProvider}" itemRenderer="myItemRenderer" />

然后,加载 xml(使用 urlLoader)并在结果中执行:

_listDataProvider = new XMLListCollection(xml..Person);

XMLListCollection 构建正常(我可以在调试中看到它)。

我做错了什么????

谢谢各位...

I'm making a LIST container with my own item renderer to display xml file.

Now, I'm overriding the public override function set data(value:Object):void method in my item renderer, the problem is that this function been called many times(!!) (more then the data provider length).

Maybe I'm not setting the data provider right, here is how I do it:

First declare bindable property:

[Bindable]
private var _listDataProvider:XMLListCollection;

Then, creating LIST object:

<mx:List id="list" dataProvider="{_listDataProvider}" itemRenderer="myItemRenderer" />

Then, loading the xml (with urlLoader) and in the result doing:

_listDataProvider = new XMLListCollection(xml..Person);

The XMLListCollection build-up ok (I can see it in debug).

What am I doing wrong?????

Thanks guys...

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

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

发布评论

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

评论(1

明媚如初 2024-08-28 01:51:27

在我看来,这是正确的,我有一种感觉,Flex 3 List 和相关的 dataProvider 组件将在第一轮中为每个项目渲染器设置几次数据(框架效率低下)。第一次,他们可能会将其设置为 null(会发生这种情况吗?),然后下次他们可能会将其设置为该值。

要解决这个问题,只需执行以下操作:

public function set data(value:Object):void
{
    if (super.data == value) 
        return;
    super.data = value;
}

这应该可以解决问题。

It looks right to me, I have a feeling the Flex 3 List and related dataProvider components will set the data a few times for each item renderer the first round (inefficiencies in the framework). The first time, they might set it to null (is that happening?), then the next time they might set it to the value.

To get around this, just do something like:

public function set data(value:Object):void
{
    if (super.data == value) 
        return;
    super.data = value;
}

That should do the trick.

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