ExtJS-UI组件-TreePanel
ExtJS教程汇总:https://www.cnblogs.com/cqpanda/p/16328016.html
转载请注明出处:https://www.cnblogs.com/cqpanda/p/16587500.html
更新记录
2023年1月2日 从笔记迁移到博客。
Ext.tree.Panel
实例:基本使用#
//Start by defining an Ext.data.TreeStore to load our data into:
let store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'treeData.json'
},
root: {
text: 'Countries',
expanded: true
}
});
//测试使用的从后端加载的treeData.json内容
[
{
"text": "United Kindom",
"leaf": false
"children": [
{
"text": "Glasgow",
"leaf": true
},
{
"text": "Edinburgh",
"leaf": true
},
{
"text": "London",
"leaf": true
}
]
},
{
"text": "France",
"leaf": true
}
]
//Create the Tree Panel and render it to the document's body.
Ext.create('Ext.tree.Panel', {
title: 'Countries & Cities',
width: 500,
height: 300,
store: store,
rootVisible: false,
renderTo: Ext.getBody(),
style: 'margin: 50px'
});
实例:排序#
在treestore中创建sorters配置项即可
var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'treeData.json'
},
root: {
text: 'Countries',
expanded: true
},
//排序器
sorters: [
{
property: 'text',
direction: 'ASC' //for descending change to 'DESC'
}
]
});
实例:复杂排序#
使用Complex and custom sorting
sorterFn配置项即可
var nameLengthSorter = function(objectOne, objectTwo){
var objectOneLength = objectOne.get('text').length,
objectTwoLength= objectTwo.get('text').length;
if(objectOneLength=== objectTwoLength){
return 0;
} else if(objectOne
Length<objectTwoLength){
return -1;
} else {
return 1;
}
};
//然后
sorters: [
{
sorterFn: nameLengthSorter,
direction: 'ASC' //for descending change to 'DESC'
}
]
实例:对多个字段排序#
sorters: [
{
property: 'text',
direction: 'ASC'
},
{
property: 'continent',
direction: 'DESC'
}
]
实例:后期排序#
调用store的sort方法即可
store.sort('text');
//or we can force a direction like so:
store.sort('text', 'DESC');
实例:树之间拖拽节点#
Dragging-and-dropping nodes within a tree
enableDrop: true sets the tree to accept drop gestures
enableDrag: false stops the users from dragging nodes within from this TreeView
allowContainerDrop: true allows the user to drop anywhere in the tree's container
//树1:
plugins: {
ptype: 'treeviewdragdrop'
}
//树2:
plugins: {
ptype: 'treeviewdragdrop',
enableDrop: true,
enableDrag: false,
allowContainerDrop: true
}
作者:重庆熊猫
出处:https://www.cnblogs.com/cqpanda/p/17019703.html
版权:本作品采用「不论是否商业使用都不允许转载,否则按3元1字进行收取费用」许可协议进行许可。
本文来自博客园,作者:重庆熊猫,转载请注明原文链接:https://www.cnblogs.com/cqpanda/p/17019703.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通