ExtJS-Data Package (数据处理包) TreeModel类型

更新记录
2022年7月13日 发布。
2022年7月6日 从笔记迁移到博客。

ExtJS教程汇总:https://www.cnblogs.com/cqpanda/p/16328016.html

Ext.data.TreeModel(树型模型)

说明#

Ext.data.TreeModel用于表示树型模型
Ext.data.TreeModel继承自Ext.data.Model
常用于配合Ext.data.TreeStore使用

实例:定义TreeModel#

//定义TreeModel
Ext.define('BizDash.model.NavigationItem', {
    extend: 'Ext.data.TreeModel',  //继承自TreeModel
    fields: [   //定义字段
        { name: 'Label', type: 'string' },
        { name: 'Route', type: 'string' }
    ]
});

实例:添加子节点#

appendChild: This adds the specified node(s) as the last child of the current node

//定义TreeModel
Ext.define('BizDash.model.NavigationItem', {
    extend: 'Ext.data.TreeModel',  //继承自TreeModel
    fields: [   //定义字段
        { name: 'Label', type: 'string' },
        { name: 'Route', type: 'string' }
    ]
});

//定义TreeModel的实例
var treeModelInstance = Ext.create('BizDash.model.NavigationItem');

//添加子节点
treeModelInstance.appendChild({
    Label: 'Orders',
    Route: '/orders'
});

//添加子节点(多个)
treeModelInstance.appendChild([{
    Label: 'Orders',
    Route: '/orders'
},{
    Label: 'First',
    Route: '/first'
}]);

实例:插入子节点#

insertChild: This inserts the new node at the specified position

//定义TreeModel
Ext.define('BizDash.model.NavigationItem', {
    extend: 'Ext.data.TreeModel',  //继承自TreeModel
    fields: [   //定义字段
        {
            name: 'Label',
            type: 'string'
        },
        {
            name: 'Route',
            type: 'string'
        }
    ]
});
//定义TreeModel的实例
var treeModelInstance = Ext.create('BizDash.model.NavigationItem');
//插入子节点
treeModelInstance.insertChild(0,{
    Label: 'First',
    Route: '/first'
});

实例:移除子节点#

removeChild: This removes the specified node from the child collection
//定义TreeModel
Ext.define('BizDash.model.NavigationItem', {
    extend: 'Ext.data.TreeModel',  //继承自TreeModel
    fields: [   //定义字段
        {
            name: 'Label',
            type: 'string'
        },
        {
            name: 'Route',
            type: 'string'
        }
    ]
});

//定义TreeModel的实例
var treeModelInstance = Ext.create('BizDash.model.NavigationItem');

//添加子节点
treeModelInstance.appendChild({
    Label: 'Orders',
    Route: '/orders'
});

//插入子节点
treeModelInstance.insertChild(0,{
    Label: 'First',
    Route: '/first'
});

//查找节点
var node = treeModelInstance.findChild('Label', 'First', true);
//移除子节点
treeModelInstance.removeChild(node);

实例:遍历子节点#

eachChild: This executes a function on each of the child nodes

//定义TreeModel
Ext.define('BizDash.model.NavigationItem', {
    extend: 'Ext.data.TreeModel',  //继承自TreeModel
    fields: [   //定义字段
        {
            name: 'Label',
            type: 'string'
        },
        {
            name: 'Route',
            type: 'string'
        }
    ]
});

//定义TreeModel的实例
var treeModelInstance = Ext.create('BizDash.model.NavigationItem');

//添加子节点(多个)
treeModelInstance.appendChild([{
    Label: 'Orders',
    Route: '/orders'
},{
    Label: 'First',
    Route: '/first'
}]);

//遍历子节点
treeModelInstance.eachChild(function(child){
    console.log(child);
});

实例:查找子节点#

findChild: This finds the first child that matches the given property/value given

//定义TreeModel
Ext.define('BizDash.model.NavigationItem', {
    extend: 'Ext.data.TreeModel',  //继承自TreeModel
    fields: [   //定义字段
        {
            name: 'Label',
            type: 'string'
        },
        {
            name: 'Route',
            type: 'string'
        }
    ]
});
//定义TreeModel的实例
var treeModelInstance = Ext.create('BizDash.model.NavigationItem');
//查找节点
var node = treeModelInstance.findChild('Label', 'First', true);

实例:检测是否叶子节点#

isLeaf: This determines if the current node is a leaf without any further children

//定义TreeModel
Ext.define('BizDash.model.NavigationItem', {
    extend: 'Ext.data.TreeModel',  //继承自TreeModel
    fields: [   //定义字段
        {
            name: 'Label',
            type: 'string'
        },
        {
            name: 'Route',
            type: 'string'
        }
    ]
});

//定义TreeModel的实例
var treeModelInstance = Ext.create('BizDash.model.NavigationItem');

//添加子节点(多个)
treeModelInstance.appendChild([{
    Label: 'Orders',
    Route: '/orders'
},{
    Label: 'First',
    Route: '/first'
}]);

//检测是否叶子节点
var node = treeModelInstance.findChild('Label', 'First', true);
console.log(node.isLeaf()); //false

作者:重庆熊猫

出处:https://www.cnblogs.com/cqpanda/p/16452706.html

版权:本作品采用「不论是否商业使用都不允许转载,否则按3元1字进行收取费用」许可协议进行许可。

posted @   重庆熊猫  阅读(179)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示