evant
18 Jun 2007, 12:10 AM
An issue I've had with an Ext app is that when loading a tree asynchronously, on the server side I already know that the node has no children, however as far as I can tell there is no easy way to communicate this back to Ext (please correct me if there is an easier way).
So, if you know beforehand that your node is empty, when sending the JSON back to the client, include:
{isLoaded: true}
for the appropriate nodes.
Then in your tree code, use:
tree.on('beforeload', function(node)
{
if (node.attributes['isLoaded'])
return false; //we know the node is empty, don't querying the server
}, this);
tree.on('load', function(node)
{
var children = node.childNodes;
for (var i = 0; i < children.length; i++)
{
var n = children[i];
if (n.attributes['isLoaded'])
n.expand(); //force the node to expand
}
}, this);
This technique is useful when there is not necessarily always a leaf node (a folder structure would be a good example of this).
So, if you know beforehand that your node is empty, when sending the JSON back to the client, include:
{isLoaded: true}
for the appropriate nodes.
Then in your tree code, use:
tree.on('beforeload', function(node)
{
if (node.attributes['isLoaded'])
return false; //we know the node is empty, don't querying the server
}, this);
tree.on('load', function(node)
{
var children = node.childNodes;
for (var i = 0; i < children.length; i++)
{
var n = children[i];
if (n.attributes['isLoaded'])
n.expand(); //force the node to expand
}
}, this);
This technique is useful when there is not necessarily always a leaf node (a folder structure would be a good example of this).