在 ExtJS 中,如果您使用 Ext.data.TreeStore 请求返回的数据格式为 [{ text: 1, id: 1, expanded: true, children: [{ id: 11, text: '11' }, { id: 12, text: '12' }] }, { text: 2, id: 2 }],而您只想展示数据的第一项,可以使用以下方法:

在创建 TreePanel 时,设置 rootVisible 属性为 false。这样,只会展示从 TreeStore 返回的数据的第一项,而不会显示根节点。

示例代码如下:

Ext.create('Ext.tree.Panel', {
    store: Ext.create('Ext.data.TreeStore', {
        root: {
            text: 'Root',
            expanded: true,
            children: [{
                text: 1,
                id: 1,
                expanded: true,
                children: [{
                    id: 11,
                    text: '11'
                }, {
                    id: 12,
                    text: '12'
                }]
            }, {
                text: 2,
                id: 2
            }]
        }
    }),
    rootVisible: false, // 设置 rootVisible 为 false
    renderTo: Ext.getBody()
});

通过设置 rootVisiblefalse,您就可以轻松地只展示 TreeStore 数据的第一项,而不需要对数据进行额外的处理。

ExtJS TreePanel 如何只展示 TreeStore 数据的第一项

原文地址: https://www.cveoy.top/t/topic/mkUY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录