PDA

View Full Version : Problem with the TreeStore "beforeappend" event



brunofin
26 Jun 2014, 9:31 AM
Hello,

According to ExtJS 4.2.0 documentation about TreeStore's "beforeappend" event, if I will return false, the node will not be appended (the operation will be canceled).

http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.data.TreeStore-event-beforeappend

So I have a node with a property parentGuid, and in case this property is set, I don't want to append this node to the tree (it will be added later as a child of a node which have the matching guid property).

The function is like this:



listeners: {
beforeappend: function(self, node, eOpts) {
if (node.data.parentGuid != '' || node.data.parentGuid != null) {
return false;
}
}
}


The problem is that it actually cancels the whole operation and does not add any other node to the tree after this one, and in the console, an error is displayed:



Uncaught TypeError: Cannot set property '{00000000-0000-0000-0000-000000000002}' of undefined

This property is the supposed parentGuid, but why is it trying to set it, if I am only reading it? Where is the problem here?

Thanks.

brunofin
26 Jun 2014, 9:58 AM
OK, just changing the function to:


listeners: {
beforeappend: function(self, node, eOpts) {
if (node.data.parentGuid) {
return false;
}
}
}


Made it work. Maybe it was just lack of basics in JavaScript? :">