更改Ext.js TreePanel复选框元素

时间:2017-03-17 01:26:31

标签: javascript jquery json node.js extjs

我有Ext.js的基本treepanel复选框示例,如下所示:

Ext.onReady(function(){
    var tree = new Ext.tree.TreePanel({
        renderTo:'tree-div',
        title: 'My Task List',
        height: 300,
        width: 400,
        useArrows:true,
        autoScroll:true,
        animate:true,
        enableDD:true,
        containerScroll: true,
        rootVisible: false,
        frame: true,
        root: {
            nodeType: 'async'
        },

        // auto create TreeLoader
        dataUrl: 'check-nodes.json',

        listeners: {
            'checkchange': function(node, checked){
                if(checked){
                    node.getUI().addClass('complete');
                }else{
                    node.getUI().removeClass('complete');
                }
            }
        },

        buttons: [{
            text: 'Get Completed Tasks',
            handler: function(){
                var msg = '', selNodes = tree.getChecked();
                Ext.each(selNodes, function(node){
                    if(msg.length > 0){
                        msg += ', ';
                    }
                    msg += node.text;
                });
                Ext.Msg.show({
                    title: 'Completed Tasks', 
                    msg: msg.length > 0 ? msg : 'None',
                    icon: Ext.Msg.INFO,
                    minWidth: 200,
                    buttons: Ext.Msg.OK
                });
            }
        }]
    });

    tree.getRootNode().expand(true);
});

这适用于check-nodes.json:

[{
    text: 'To Do', 
    cls: 'folder',
    children: [{
        text: 'Go jogging',
        id: 'test',
        leaf: true,
        checked: false
    },{
        text: 'Take a nap',
        leaf: true,
        checked: false
    },{
        text: 'Climb Everest',
        leaf: true,
        checked: false
    }]
}]

所以Ext.js会尝试将这些json数据转换为html输入复选框,如下所示: enter image description here

有没有办法更改输入复选框的ID? 我试图在json文件“id:test”设置密钥Id,但它返回html脚本,如下所示: enter image description here 对它有影响的“ext:tree-node-id = test”,我只需要设置这样的东西 “<input class="x-tree-node-cb" type="checkbox" id="test">” 有没有办法做到这一点?谢谢

1 个答案:

答案 0 :(得分:1)

将输入复选框更改为:

xtype:&#39;复选框&#39;,
id:&#39; hidetypecheckbox&#39;,

关心
MH