简体   繁体   English

在ExtJs 4.1中使用其ID在树节点上触发checkchange事件

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

I have a TreePanel. 我有一个TreePanel。 Each node in tree is given an ID. 树中的每个节点都有一个ID。 On click of a button, I want to fire the checkchange event for node 2.1 (as shown in the below tree). 单击按钮后,我要触发节点2.1的checkchange事件(如下树所示)。 How can I fire checkchange event for a node using its ID on click of a button. 单击按钮如何使用节点ID触发节点的checkchange事件。

  1 
      1.2
      1.3
      1.4
  2
       2.1
       2.2
  3

Thank you 谢谢

To fire the checkchange you need to have the node and if it's checked. 要触发checkchange,您需要拥有节点以及是否已对其进行检查。

The TreePanel is using Ext.data.TreeStore to store it's nodes information (it is in the store property). TreePanel使用Ext.data.TreeStore来存储其节点信息(位于store属性中)。

This TreeStore has the getNodeById( id ) method which returns the record node by id. 此TreeStore具有getNodeById( id )方法,该方法按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. 如果要从另一个属性获取节点,则需要使用storetreeExt.data.Tree )属性,就像节点管理器一样。 This has a node record array in the nodeHash property. 它在nodeHash属性中具有一个节点记录数组。 You need to iterate this Array and compare the given property manually. 您需要迭代此Array并手动比较给定的属性。

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'));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM