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字进行收取费用」许可协议进行许可。
本文来自博客园,作者:重庆熊猫,转载请注明原文链接:https://www.cnblogs.com/cqpanda/p/16452706.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?