判断数据是否脏的简单方法
我目前正在一组 Spark 表单元素上使用数据绑定,并想知道我绑定的数据类是否脏。
如果 Spark“Form”元素能够触发一个冒泡并被 Spark“Form”捕获的更改事件,那么可能会很好。然后我可以向表单添加一个事件侦听器。但我没有看到这样的事情。
因此,除了将原始数据类的副本与绑定数据类进行比较或向每个表单元素添加更改事件并捕获该事件之外,还有什么简单的方法可以了解类对象已更改?
I am currently using databinding on a group of spark form elements and want to know if the data class I am bound to is dirty.
It might be nice if spark "Form" elements would trigger a change event that bubbled up to and was caught by a spark "Form". Then I could just add an event listener to the form. But I don't see something like that.
So besides comparing a copy of the original data class to the bound data class OR adding a change event to each form element and capturing that event, what's an easy way of knowing a class object has changed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
扩展 TextInput 或表单中的任何其他输入元素,然后在组件创建中完成注册更改事件的侦听器,在处理程序中分派冒泡事件,然后在包含表单的文档中使用您的自定义元素并通过 AS3 将侦听器添加到您调度的事件的表单中,并在此时停止其传播。
否则我认为每个更改处理程序的第二个解决方案不会太糟糕。如果表单中有很多元素或者它是动态的,您可以编写一个函数来逐步执行表单的表单项并检查它们的子项,然后您只需编写一个处理每个类类型的开关(您可以使用 < a href="http://www.actionscriptdeveloper.co.uk/getting-the-class-of-an-object-in-as3/on" rel="nofollow">http://www.actionscriptdeveloper.co.uk/getting-the-class-of-an-object-in-as3/on 每个子元素以确定其类型,那么如果它是 TextInput 或任何注册适当事件来调用常用函数的内容,只需确保它有一个通用事件作为参数,因为所有其他事件都将是其子类)。
据我所知,没有简单的方法可以监听 ArrayCollection 或其他包装器 ListCollectionView 数据结构中底层数据的更改。部分问题是添加到集合中的元素不需要实现任何类型的接口来允许注册侦听器。也就是说,数据元素不一定是事件调度程序,将此信息传递到列表的唯一其他方式是,如果数据元素在包含该元素的所有列表上都有句柄,并且它们在列表上标记某些内容,设置任何属性时指示“脏”。这些在语言的限制内都是可以实现的,但并不是开箱即用的,因为它们的使用可能是有限的,并且在其他情况下可能会不必要地增加 ListCollectionView 的 cpu 使用率。
Make an extension of TextInput or whatever other input elements you'll have in your form then in your components creation complete register a listener for the change event, in the handler dispatch a bubbling event, then in your document that contains the form use your custom elements and add a listener via AS3 to the Form for the event you dispatched and stop it's propagation at that point.
Otherwise I think your second solution of change handler on each wouldn't be too bad. If you have a lot of elements in the form or it's dynamic you could write a function that steps through the form items of the form and checks their children then you just have to write a switch that deals with each class type (you can use http://www.actionscriptdeveloper.co.uk/getting-the-class-of-an-object-in-as3/on each of the child elements to determine what type it is, then if it's a TextInput or whatever register the appropriate event to call your commonly used function, just be sure it has a generic Event as it's parameter since all other Events will be sub-classes thereof).
So far as I know there is no easy way to listen for changes to the underlying data from the ArrayCollection or other wrapper ListCollectionView data structures. Part of the problem is the elements added a collection aren't required to implement any sort of interface to allow for listeners to be registered. That is, the data elements aren't necessarily event dispatchers, the only other way for this information to be communicated to the List would be if the data elements had a handle on all lists that contain that element and they mark something on the lists to indicate "dirty" when any property is set. These are all achievable within the constraints of the language but aren't provided out of the box as the usage for them is probably limited and could potentially unnecessarily bloat the cpu usage of the ListCollectionView in other cases.