简体   繁体   English

ExtJS 4.2.1,Tree,将子节点添加到节点

[英]ExtJS 4.2.1 , Tree, adding children to a node

I am working with ExtJS 4.2.1 我正在使用ExtJS 4.2.1

I am trying to append children to a leaf when I click on it. 当我点击它时,我正试图将孩子贴在一片叶子上。 It initially is a leaf, the click transform it into a folder and I would like to append leaves as children to this node. 它最初是一个叶子,点击将其转换为一个文件夹,我想将叶子作为子项附加到此节点。

It worked in Ext 3.4 but it seems there is a problem with the appendChild() method in 4.2.1. 它在Ext 3.4中工作,但似乎4.2.1中的appendChild()方法存在问题。 I get an Uncaught TypeError: Object [object Object] has no method 'updateInfo' from this method due to node.updateInfo(commit); 我得到一个Uncaught TypeError: Object [object Object] has no method 'updateInfo'由于node.updateInfo(commit); Uncaught TypeError: Object [object Object] has no method 'updateInfo'来自此方法的Uncaught TypeError: Object [object Object] has no method 'updateInfo' node.updateInfo(commit); that we can find in appendChild() . 我们可以在appendChild()找到。

This is a pretty simple instruction: 这是一个非常简单的指令:

In Ext3 在Ext3中

    node.leaf = false; 
        // add nodes in trees
        for  ( i =0 ; i < timesheetData.length ; i++ ) 
        {
            // we create a new node and state it's a timesheet 
            var newNode =  new Ext.tree.TreeNode({
                 id : timesheetData[i].id, 
                 text : timesheetData[i].text, 
                 ts : true }) ;
            node.appendChild(newNode);

        } 
    node.expand(); 

In Ext4 在Ext4中

    node.set('leaf', false); 
        // add nodes in trees
        for  ( i =0 ; i < timesheetData.length ; i++ ) 
        {

            node.appendChild({
                 id : timesheetData[i].id, 
                 text : timesheetData[i].text, 
                 ts : true });

        } 
    node.expand();

Ext.tree.TreeNode doesn't exist anymore in 4.2.1. 在4.2.1中不再存在Ext.tree.TreeNode So I try to append the child directly. 所以我试着直接追加孩子。 But it doesn't work! 但它不起作用!

What could I do? 我能做什么?

Thank you 谢谢

Try this in your tree listener: 在树监听器中尝试这个:

itemclick: function( record, item, index, e, eOpts ){
            item.appendChild({
                text: 'Hi! I am a leaf',
                leaf: true
            });
           }

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

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