手动调度集合更改事件
我有一个标准组合框,当数据提供者完成初始化时调度集合事件:
my_cb.addEventListener( CollectionEvent.COLLECTION_CHANGE, getMyStuff );
然后我有一个自定义组件,它也有一个 dataProvider。当其数据提供者完成加载时,如何让它调度集合更改事件?
从我读到的来看,我做不到。调度 propertychange 事件有效吗?
感谢您提供任何有用的提示!
更新:
我有一个自定义组件,我称之为“SortingComboBox”,但它根本不是一个 ComboBox;它扩展了 Button,我将 dataProvider 属性设置为我的数组集合 model.product (这是一个数组集合)。
以下是我在该组件中使用 dataProvider 的方式:
code
[Bindable] 私有 var _dataProvider :对象;
public function get dataProvider() : Object
{
return _dataProvider;
}
public function set dataProvider(value : Object) : void
{
_dataProvider = value;
}
code
在此组件的 createChildren() 方法中,我使用:
BindingUtils.bindProperty(dropDown, "dataProvider", this, "dataProvider");
dropDown 是一个自定义 VBox,我用它来显示标签。
I have a standard combobox that dispatches a collection event when the dataprovider finishes initializing:
my_cb.addEventListener( CollectionEvent.COLLECTION_CHANGE, getMyStuff );
Then I have a custom component that also has a dataProvider. How do I get it to dispatch a collection change event when its dataprovider finishes loading?
From what I've read, I can't do it. Will dispatching a propertychangeevent work?
Thanks for any helpful tips!
UPDATE:
I have a custom component that I call 'SortingComboBox' but it is not a ComboBox at all; it extends Button and I set is dataProvider property to my arraycollection, model.product (which is an arraycollection).
And here is how I use the dataProvider in that component:
code
[Bindable]
private var _dataProvider : Object;
public function get dataProvider() : Object
{
return _dataProvider;
}
public function set dataProvider(value : Object) : void
{
_dataProvider = value;
}
code
In the createChildren() method of this component, I use this:
BindingUtils.bindProperty(dropDown, "dataProvider", this, "dataProvider");
The dropDown is a custom VBox that I use to display labels.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当您调用 setter 时,您必须确保
1) 您实际上正在使用 setter 更改值。因此,即使您在类内部,也请调用 this.dataProvider = foo 而不是 _dataProvider = foo
2) 除非您实际更改值,否则绑定不会触发。如果您跟踪,您会发现 setter 实际上调用了 getter,如果传递给 setter 和 getter 的值相同,则不会发生绑定。
您的另一个选择是在 getter 上放置一个事件,然后调用它来触发绑定。
When you call the setter, you have to make sure
1) that you actually are changing the value with the setter. So even if you are inside the class, call this.dataProvider = foo instead of _dataProvider = foo
2) The binding will not trigger unless you actually change the value. If you trace you'll see that the setter actually calls the getter, if the values of what you pass into the setter and the getter are the same, the binding will not occur.
Your other option is to put an event on the getter, then just call it to trigger the binding.
使您的数据提供者可绑定
Make your dataprovider bindable
数据绑定是 ActionScript/Flex 所独有的。
除此之外,它还会调度更改事件。
也许如果您发布自定义组件的代码,我可以更具体。
实际上你能解释一下你想要实现的目标是什么吗?
我只能告诉你你正试图让一个按钮有一个下拉菜单。
为什么?
Data binding is something unique to ActionScript/Flex.
Among other things it will dispatch change events.
Maybe if you post your code for the custom component I can be more specific.
Actually can you explain what your goal is you are trying to achieve?
All I can tell is you are trying to make a button have a drop down.
Why?
这是自定义组件,只是为了给您一个更好的想法。
代码
包 com.fidelity.primeservices.act.components.sortingcombobox
{
导入 com.fidelity.primeservices.act.events.component.ResetSortEvent;
导入 com.fidelity.primeservices.act.events.component.SortEvent;
}
this is the custom component just to give you a better idea.
code
package com.fidelity.primeservices.act.components.sortingcombobox
{
import com.fidelity.primeservices.act.events.component.ResetSortEvent;
import com.fidelity.primeservices.act.events.component.SortEvent;
}
好吧,这里的代码
没有什么不同,
因为对象是通过引用传递的,所以你无论如何都不会保护它,并且 setter 和 getter 是没有意义的。
另一方面,您使源 _dataProvider 可绑定,因此只要数据发生更改,它就会调度 CollectionEvent.COLLECTION_CHANGE
Ok this code here
is no different then
Since objects are passed by reference you are not protecting it in anyway and the setter and getter are pointless.
On the other hand you made the source _dataProvider Bindable so anytime the data changes it will dispatch a CollectionEvent.COLLECTION_CHANGE