如何按特定顺序更新多个可绑定属性? (弹性)

发布于 2024-11-02 17:07:03 字数 603 浏览 1 评论 0原文

我有一种情况需要更新 DropDownList 的 dataProvider 和 selectedItem 按特定顺序。请参阅以下代码...

<s:DropDownList id="dropDownList"
                dataProvider="{someDataProvider}"
                selectedItem="{someSelectedItem}" />

在我的例子中,某些用户交互会为可绑定变量“someDataProvider”和“someSelectedItem”生成新值。然而,当flex渲染DropDownList时,控件的选定值为空。

原因是 DropDownList 的“selectedItem”属性在“dataProvider”属性之前绑定。为了使“selectedItem”有效,需要首先绑定“dataProvider”,这是因为新的“selectedItem”指向新的“dataProvider”。

我的问题是,以特定顺序更新可绑定属性的最佳实践是什么?我想出了几种方法(例如使用 valueCommit 处理程序),但是我想看看社区怎么说。

I have a situation where I need to update a DropDownList's dataProvider and selectedItem
in a specific order. See the following code ...

<s:DropDownList id="dropDownList"
                dataProvider="{someDataProvider}"
                selectedItem="{someSelectedItem}" />

In my case, some user interaction produces new values for the bindable variables "someDataProvider", and "someSelectedItem". However, when flex renders the DropDownList, the control's selected value is empty.

The reason for this is that the DropDownList's "selectedItem" property gets bound before the "dataProvider" property. The "dataProvider" needs to be bound first for "selectedItem" to be valid, this is because the new "selectedItem" points into the new "dataProvider".

My question is, what is the best practice for updating bindable properties in a specific order? I've come up with a few ways (e.g. using a valueCommit handler), but I wanted to see what the community had to say.

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

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

发布评论

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

评论(2

紫罗兰の梦幻 2024-11-09 17:07:03

我认为问题不在于形成数据提供者和所选项目的顺序。如果它们在将它们设置到列表后形成在同一个 Flash Player 的框架中,则它们不会立即应用。 Flex 使用失效将实际操作推迟到下一帧。

为了解决您的问题,请发布更多代码。如果您能发布形成数据的代码,那就太好了。

您的 selectedItem 是否有可能实际上不是您的数据提供程序的成员(某种克隆等)?您的数据提供程序中的对象是什么类型?

I don't think the problem is in order of forming data provider and selected item. If they form in the same Flash Player's frame after setting them into List they don't apply immediately. Flex uses invalidation to postpone real actions to the next frame.

To solve your problem please post more code. It will be good if you'll post code which forms data.

Is it possible that your selectedItem isn't really a member of your data provider (some kind of clone or so)? Objects of what type in your data provider?

残龙傲雪 2024-11-09 17:07:03

这是一个困扰我很久的问题。有道理,但又没有道理。如果数据更改,您希望清除 selectedItem,但前提是数据实际上不同或不包含您所选择的项目。

就我个人而言,我只会创建一个扩展 DropDownList 的自定义组件并覆盖 dataProvider、selectedItem 和 commitProperties 以防止清除 selectedItem。

It's a problem that has annoyed me for a long time. It makes sense, but doesn't. You'd want the selectedItem to be cleared if the data changes, but only if the data is actually different or doesn't hold your selected item.

Personally, I would just create a custom component extending the DropDownList and overriding the dataProvider, selectedItem and commitProperties to prevent clearing the selectedItem.

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