-
7 Dec 2007 3:33 PM #11
Workaround
Workaround
I guess this bug wasn't fixed for the 2.0 release. Shame. For the other posters, here's a workaround that I'm playing with that SEEMS to work all right thus far.
The custom loader prevents needless XHR requests.
The event handler 'expands' the leaf nodes to get the right icon (and more importantly, to eliminate the expand toggle).PHP Code:
// custom treeloader so that we can treat '!has_children' more or less as
// leaf, but still take advantage of the default drag & drop (which, by
// default, will not allow appends to leaf - see possible bug
// http://extjs.com/forum/showthread.php?t=17522&highlight=drop+leaf+node
// - this is only needed (in leiu of leaf => true|false) because we
// allowing appending to 'leaf' nodes, dynamically turning them into
// interior nodes
var treeLoader =new Ext.tree.TreeLoader({
dataUrl: '/resource/children'
})
treeLoader.on('beforeload', function(tree, node) {
if(node.attributes.has_children == false)
return false
})
config = config || {}
MyClass.superclass.constructor.call(this, Ext.apply({
el: 'pad',
loader: treeLoader,
autoScroll: true,
animate: true,
enableDD: true,
containerScroll: true
// , ... other params for toolbar, etc.
},config))
With the above, I make sure that children are loaded with no 'leaf' attribute (letting it default to false), but with has_children set appropriately.PHP Code:this.on('append', function(tree, parentNode, newNode, newNodeIndex) {
if(newNode.attributes.has_children == false) {
newNode.render()
newNode.expand(false)
}
})
-
5 Jan 2008 7:14 AM #12
for Ext 1.1.1 find in ext-all.js:
and replase on:var H=J.allowChildren===false||J.isLeaf();
var H=J.allowChildren===false;
-
8 Jan 2008 11:29 AM #13
great change, but how do you manage the icon?
great change, but how do you manage the icon?
If I add the following to my ext-all.js with the 1.1 version. My leaf does accept children however, the icon for the node remains a leaf and not a folder. Do you know how I would go about declaring the image of the said node to automatically have the folder icon?
var H=J.allowChildren===false;
-
28 Jan 2008 11:21 PM #14
我的办法是重载Ext.data.Node,添加一个setLeaf方法,然后在tree的append事件中把节点的leaf都设为false。
PHP Code:Ext.override(Ext.data.Node, {
setLeaf: function(value){
this.leaf = value;
}
});
欢迎加入37921608群(QQ)一起研讨Ext。PHP Code:this.on('append',function(tree,p,n,index){
n.setLeaf(false);
});
-
18 Feb 2008 6:46 AM #15
Thxs. That solved my problem.
To the general discussion about bug/no-bug:
Testing for isLeaf() is not realy the bug. It-s OK. leaf==tue means that the node may never have children (like a document in a directory tree).
The bug is however, that the treeloader automaticaly adds a plus sign if leaf==false (therefore you may never have empty directories)
The plus sign should only triggerd by something like node.hasChildren and nothing else.
-
5 May 2009 8:54 PM #16
I believe that I have found an incredibly simple solution to this problem.
When the server returns the JSON response for the tree I add the following parameters:
And to the TreePanel I add:Code:'expanded' => !$node->hasChildren(), 'loaded' => !$node->hasChildren()
So basically, if the node has no children then it still isn't a leaf (because a leaf can't have children) but as far as the TreePanel is concerned it has already been expanded and had it's children loaded.Code:baseAttrs: { allowChildren: true, leaf: false }
expanded - Expands the node and (as the node has no children) displays a page icon instead of a folder icon.
loaded - Tells TreePanel not to make another request to get this nodes children, so no extra HTTP request and no spinning loading icon.
This has worked perfectly for me and is very simple.Last edited by Keri Henare; 5 May 2009 at 8:59 PM. Reason: No sig
-
12 Aug 2009 9:05 AM #17
Thanx Keri, this is exactly the simple solution I was searching for.
Romanticus
-
13 Sep 2012 1:19 AM #18
Thanks!
Thanks!
Thanks again Keri, excellent sollution and it still works for Ext 4.1 !


Reply With Quote

