PDA

View Full Version : How to trigger a double click event to tree nodes



albertpeng
10 Nov 2010, 11:49 AM
I came across a problem when I was trying to trigger a double click event to tree nodes. The code below is someone’s online, creating a tree when loading Google Map file in KML format. What I would like to do is to double click a tree node and some function can be trigged. Please give me the exact solution and code as I am a beginner of ExtJs. I appreciate your help in advance.



// Create KML tree (called by above function)
treeNodeFromKml: function(kmlObject){
var result = this.createKmlTreeNode(kmlObject);
if(kmlObject.getFeatures().hasChildNodes()) {
var subNodes = kmlObject.getFeatures().getChildNodes();
for(var i = 0; i < subNodes.getLength(); i++) {
var subNode = subNodes.item(i);
switch(subNode.getType()) {
case 'KmlFolder' :
var node = this.treeNodeFromKml(subNode); // Recursion
break;
default:
var node = this.createKmlTreeNode(subNode);
break;
}
result.appendChild(node);
}
}
return result;
},
// Create KML tree node (called by above function)
createKmlTreeNode: function(kmlEl){
var node = new Ext.tree.TreeNode({
text: kmlEl.getName(),
checked: (kmlEl.getType() != 'KmlPlacemark' ? (kmlEl.getVisibility() ? true : false) : null),
expanded: (kmlEl.getOpen() ? true : false),
iconCls: kmlEl.getType(),
kml: kmlEl
});
return node;
}

darthwes
10 Nov 2010, 12:23 PM
// Create KML tree (called by above function)
treeNodeFromKml: function (kmlObject) {
var result = this.createKmlTreeNode(kmlObject);
if (kmlObject.getFeatures().hasChildNodes()) {
var subNodes = kmlObject.getFeatures().getChildNodes();
for (var i = 0; i < subNodes.getLength(); i++) {
var subNode = subNodes.item(i);
switch (subNode.getType()) {
case 'KmlFolder':
var node = this.treeNodeFromKml(subNode); // Recursion
break;
default:
var node = this.createKmlTreeNode(subNode);
break;
}
node.on('dblclick', someFn, someFnScope);
result.appendChild(node);
}
}
return result;
},
// Create KML tree node (called by above function)
createKmlTreeNode: function (kmlEl) {
var node = new Ext.tree.TreeNode({
text: kmlEl.getName(),
checked: (kmlEl.getType() != 'KmlPlacemark' ? (kmlEl.getVisibility() ? true : false) : null),
expanded: (kmlEl.getOpen() ? true : false),
iconCls: kmlEl.getType(),
kml: kmlEl
});
return node;
}

albertpeng
14 Nov 2010, 2:08 AM
Thanks a lot. It is working perfectly