简体   繁体   English

Flex数据绑定问题

[英]Flex Data Binding problem

<mx:Label text="{(item1 as INewsItem).displayName}"/>

For the above code in Flex, I get this warning : 对于Flex中的上述代码,我收到此警告:

: Data binding will not be able to detect assignments to item1. :数据绑定将无法检测到item1的分配。
Why? 为什么? How to Fix it? 如何解决?

If you define a [Bindable] function get item1() you'll also need to define a function set item1() , otherwise Flex wouldn't know when to dispatch a change event. 如果你定义一个[Bindable] function get item1()你还需要定义一个function set item1() ,否则Flex将不知道何时调度一个change事件。 Or you could manually dispatch the change event: 或者您可以手动调度更改事件:

[Bindable(event="item1Change"]
public function get item1() { return ... }

And whenever something on item1 changes you dispatch an event: 每当item1上的某些内容发生变化时,您就会发送一个事件:

dispatchEvent(new Event("item1Change"));

The warning is displayed because the databinding will not be refreshed automatically when item1 is updated. 显示警告是因为更新item1时不会自动刷新数据绑定。 If you do want this behaviour, then you cannot use this databinding and will have to update the label text manually when item1 is changed. 如果您确实需要此行为,则无法使用此数据绑定,并且必须在更改item1时手动更新标签文本。

Thanks Prutswonder. 谢谢Prutswonder。
Actually item1 is declared as a getter, 实际上item1被声明为getter,
like this : 像这样 :

public function get item1() 

So, I had to prepend it like this : 所以,我必须像这样前置它:

[Bindable] public function get item1()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM