当 XML 被附加时,我可以触发changeWatcher吗?
因此,我需要向我的应用程序添加撤消功能,并且我发现了这个漂亮的 ChangeWatcher 类,但它并没有完全满足我的要求,我希望有人知道如何做。
ChangeWatcher 似乎监视对变量引用的分配。因此,当我说:
myXML = <xml/>
它会触发它的函数,但当我说:
myXML.appendChild(thisOtherXMLVar)
我什么也没得到,即使变量更改了引用也没有,所以 ChangeWatcher 不会触发该函数。
那么有人知道如何让 ChangeWatcher 获取变量的所有更改吗?
So I had a requirement to add an undo function to my app and I discovered this nifty ChangeWatcher class, but it's not doing exactly what I want and I'm hoping someone knows how.
ChangeWatcher seems to monitor assignments to the variable reference. So when I say:
myXML = <xml/>
it fires off it's function just fine and dandy, but when I say:
myXML.appendChild(thisOtherXMLVar)
I get nothing, even though the variable changes the reference doesn't so ChangeWatcher doesn't fire off the function.
So does anyone know how to get ChangeWatcher to pick up on all changes to a variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ChangeWatcher 是一个非常酷的类。但除非您想要观察变化的属性是[Bindable],否则它不会起作用。
如果您的
myXML
变量是可绑定的,那么当您将其设置为 XML 值时,它将调度一个事件(默认为propertyChange
)。 ChangeWatcher 为已声明的任何 [Bindable] 事件添加一个事件侦听器到对象。它通过获取该变量的可绑定元数据来实现此目的。但 XML 类本身没有任何 Bindable 内容,因此调用
appendChild
不会分派任何事件,ChangeWatcher 也不会工作。根据您的评论进行更新,您只需对 XML 进行所有更改,然后重置变量即可。这将导致 ChangeWatcher 注册更新。
希望有帮助,
槊
ChangeWatcher is a really cool class. But it's not going to work unless the property you're trying to watch change is [Bindable].
If you're
myXML
variable is Bindable, then when you set it to the XML value, it will dispatch an event (default ispropertyChange
). ChangeWatcher adds an event listener to the object for whatever [Bindable] events have been declared. It does this by getting the Bindable metadata for that variable.But the XML class itself doesn't have anything Bindable, so calling
appendChild
won't dispatch any events and ChangeWatcher wont work.Updating based on your comment, you can just make all of your changes to the XML and then reset the variable. That will then cause the ChangeWatcher to register the update.
Hope that helps,
Lance