hello,
i find TreeNode.isLeaf not work correct:
my tree:
var myTree = function() {
return {
init : function(id) {
// yui-ext tree
var Tree = Ext.tree;
// tree
this.tree = new Tree.TreePanel('tree_' + id, {
animate:true
, loader: new Tree.TreeLoader({
dataUrl:'source.php'
, baseParams: {root_id: id}
})
, enableDD:true
, containerScroll: true
});
// set the root node
this.root = new Tree.AsyncTreeNode({
text: 'Ext JS'
, draggable:false
, id:'source'
});
this.tree.setRootNode(this.root);
// render the tree
this.tree.render();
this.tree.on({
contextmenu: {scope:this, fn:this.onContextMenu}
, dblclick: {scope:this, fn:this.openNode}
});
this.root.expand();
}
, onContextMenu : function(node, e) {
// no browser context menu
e.stopEvent();
e.preventDefault();
console.info("root ::" + node.root);
console.info("isRoot ::" + node.isRoot);
// console.info("isRoot() ::" + node.isRoot());
console.info("node.leaf ::" + node.leaf);
console.info("node.isLeaf ::" + node.isLeaf);
console.info("node.isLeaf() ::" + node.isLeaf());
if(node.isRoot)
{
// save current node to context menu
this.rootContextMenu.node = node;
// show menu under node
this.rootContextMenu.show(node.ui.getAnchor());
}
// not working
// else if(node.isLeaf)
else if(node.leaf)
{
// save current node to context menu
this.leafContextMenu.node = node;
// show menu under node
this.leafContextMenu.show(node.ui.getAnchor());
}
The leaf node has node.leaf = true but node.isLeaf return false ;(
output (root):
root ::undefined
isRoot ::true
node.leaf ::undefined
node.isLeaf ::function () { return this.leaf === true; }
node.isLeaf() ::false
output (leaf):
oot ::undefined
isRoot ::undefined
node.leaf ::true
node.isLeaf ::function () { return this.leaf === true; }
node.isLeaf() ::false
output (not leaf):
root ::undefined
isRoot ::undefined
node.leaf ::undefined
node.isLeaf ::function () { return this.leaf === true; }
node.isLeaf() ::false
And what's wrong? If value of node.leaf equals undefined then true === node.leaf equals false.
in the function onContextMenu i get always true (root, not leaf node and on a leaf node):
, onContextMenu : function(node, e) {
alert((node.isLeaf) ? 'true':'false');
...
Sure, because isLeaf is function. Try:
, onContextMenu : function(node, e) {
alert((node.isLeaf()) ? 'true':'false');
Yes, because node.leaf is undefined. The code behaves exactly as it should. Do you know what === operator does? It compares value and type and only if both are equal it evaluates as true.
sorry i found my mistake the json return was a string not a boolean ;(
but why have ext a different handling for
is***
isRoot is a var and isLeaf is a function???
Those are design decisions of Jack.
This is not a bug. Closing thread...
in the function onContextMenu i get always true (root, not leaf node and on a leaf node):
, onContextMenu : function(node, e) {
alert((node.isLeaf) ? 'true':'false');
...
ok but
alert(node.isLeaf());
return always false ;( see debug info at the first post
BTW, have you read this: http://extjs.com/forum/showthread.php?t=8887
Allergies.. no relief?!?
Religion in the workplace? |