Firing checkchange event on a tree node using its ID in ExtJs 4.1

自古美人都是妖i 提交于 2019-12-13 02:22:31

问题


I have a TreePanel. Each node in tree is given an ID. On click of a button, I want to fire the checkchange event for node 2.1 (as shown in the below tree). How can I fire checkchange event for a node using its ID on click of a button.

  1 
      1.2
      1.3
      1.4
  2
       2.1
       2.2
  3

Thank you


回答1:


To fire the checkchange you need to have the node and if it's checked.

The TreePanel is using Ext.data.TreeStore to store it's nodes information (it is in the store property).

This TreeStore has the getNodeById( id ) method which returns the record node by id.

If you want to get the node from another property, then you need to use the tree (Ext.data.Tree) property from store, which is like a node manager. This has a node record array in the nodeHash property. You need to iterate this Array and compare the given property manually.

The complete code:

buttonClick: function(button, e, eOpts) {
        var treepanel = button.up(...).down('treepanel');
        var node = treepanel.getStore().getNodeById(yourIDHere);
        // for custom property use this:
        /*var nodeHash = treepanel.getStore().tree.nodeHash;
        var node;
        for (var x in nodeHash) {
            if (nodeHash[x].get('customProperty') == customValue) {
                node = nodeHash[x];
                break;
            }
        } */
        treepanel.fireEvent('checkchange', node, node.get('checked'));
}


来源:https://stackoverflow.com/questions/18444541/firing-checkchange-event-on-a-tree-node-using-its-id-in-extjs-4-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!