Can I get changeWatcher to fire when XML is appended to?
So I had a requirement to add an undo function to my a开发者_运维技巧pp 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?
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 is propertyChange
). 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
精彩评论