如何将在非叶节点之前显示加号的方式更改为在extjs树面板中包含任何子节点的节点之前显示plus

how to change the way showing plus before a non-leaf node into showing plus before a node containing any children in an extjs treepanel?

本文关键字:显示 子节点 plus 节点 extjs 包含任 叶节点 方式更      更新时间:2023-09-26

代码: 演示

这是来自书籍ExtJs in Action:的示例的修改后的树数据

     var store = Ext.create('Ext.data.TreeStore', {
        root: {
            text: 'Root Node',
            expanded: false,
            children: [{
                text: 'Child 1',
                leaf: false     //<---------Modified (from true to false)
            }, {
                text: 'Child 2',
                leaf: true
            }, {
                text: 'Child 3',
                children: [{
                    text: 'Grand Child 1',
                    children: [{
                        text: 'Grand... you get the point',
                        leaf: true
                    }]
                }]
            }]
        }
    });

展开Root Node时,您会发现此节点的Child 1不是叶之前有一个+。但是,Child 1中没有任何内容。

问题:
有没有什么方法可以通过判断节点中是否有子节点来改变在节点之前显示+的方式?谢谢你的帮助。

如果父级没有子级,则在JSON响应或根(在您的情况下(中将loaded属性设置为true

你的根配置应该像这个

root: {
        text: 'Root Node',
        expanded: false,
        children: [{
            text: 'Child 1',
            leaf: false,
            loaded:true
        }, {
            text: 'Child 2',
            leaf: true
        }, {
            text: 'Child 3',
            children: [{
                text: 'Grand Child 1',
                children: [{
                    text: 'Grand... you get the point',
                    leaf: true
                }]
            }]
        }]
    }