ExtJS在树面板中插入新孩子的问题

时间:2019-05-14 15:03:42

标签: extjs

我正在尝试按需填充树。我正在捕获doubleclick事件,这是控制器中的代码:

itemdblclick: function(item, record, eOpts) {
       console.log(item, record, eOpts);
       var store = Ext.getStore('mystoreid');
       var node = store.getRootNode().findChild('idelement', record.data.idelement, true);

       node.insertChild(
           {
               idelement: '100',
               descript: 'AAAAA',
               active: true,
               idparent: record.data.idelement,
               name: '01010101010',
               text: 'Show yourself, please!',
               leaf: true,
               loaded: true,
               children: []
           }
       );

       node.expand();
    }

此代码向我显示此错误:

Uncaught TypeError: Cannot read property 'isModel' of undefined
    at constructor.createNode (ext-all-debug.js:108050)
    at constructor.appendChild (ext-all-debug.js:108224)
    at constructor.insertChild (ext-all-debug.js:108790)
    at constructor.loadRecords (SelectorNiveles.js:79)
    at constructor.fire (ext-all-debug.js:20731)
    at constructor.dispatch (ext-all-debug.js:57952)
    at constructor.callParent (ext-all-debug.js:12493)
    at constructor.dispatch (ext-all-debug.js:58196)
    at constructor.prototype.doFireEvent (ext-all-debug.js:58109)
    at constructor.fireEventArgs (ext-all-debug.js:21553)

我一直在Google搜索解决方案,但未成功。我正在使用Firefox,Chromium和Extjs 6.0.2,我在做什么错了?

1 个答案:

答案 0 :(得分:0)

不知道这是否是错误的根源,但是根据docs,您需要在要添加的节点之前传递index

node.insertChild(
           0,{
               idelement: '100',
               descript: 'AAAAA',
               active: true,
               idparent: record.data.idelement,
               name: '01010101010',
               text: 'Show yourself, please!',
               leaf: true,
               loaded: true,
               children: []
           }
       );