在ExtJs 4.1中使用其ID在树节点上触发checkchange事件 [英] Firing checkchange event on a tree node using its ID in ExtJs 4.1

查看:302
本文介绍了在ExtJs 4.1中使用其ID在树节点上触发checkchange事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TreePanel.树中的每个节点都有一个ID.单击按钮后,我要触发节点2.1的checkchange事件(如下树所示).单击按钮,如何使用节点的ID触发节点的checkchange事件.

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

谢谢

推荐答案

要触发checkchange,您需要拥有节点以及是否已对其进行检查.

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

TreePanel正在使用Ext.data.TreeStore存储其节点信息(位于store属性中).

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

此TreeStore具有getNodeById( id )方法,该方法按ID返回记录节点.

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

如果要从另一个属性获取节点,则需要使用store中的tree(Ext.data.Tree)属性,就像节点管理器一样.它在nodeHash属性中具有一个节点记录数组.您需要迭代此Array并手动比较给定的属性.

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.

完整代码:

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

这篇关于在ExtJs 4.1中使用其ID在树节点上触发checkchange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆