Javascript Extjs TreePanel:如何按类或属性隐藏节点?
我有一个包含任务的节点树 已完成任务的属性状态为:100,类cls为:“完成” 我想做一个隐藏已完成任务的按钮 什么函数将根据节点的id或类隐藏树中的节点?Javascript Extjs TreePanel:如何按类或属性隐藏节点?,javascript,extjs,Javascript,Extjs,我有一个包含任务的节点树 已完成任务的属性状态为:100,类cls为:“完成” 我想做一个隐藏已完成任务的按钮 什么函数将根据节点的id或类隐藏树中的节点? {"id":"45", "description":"Pay bills", "status":"100", "cls":"done", "uiProvider":"col", "leaf":true} 尝试从根开始遍历树并测试所需的属性。如果命中,请隐藏节点: tree.getRootNode().cascade(function()
{"id":"45",
"description":"Pay bills",
"status":"100",
"cls":"done",
"uiProvider":"col",
"leaf":true}
尝试从根开始遍历树并测试所需的属性。如果命中,请隐藏节点:
tree.getRootNode().cascade(function() { // descends into child nodes
if(this.attributes['status'] == 100) { // test this node
this.getUI().hide() // hide this node
}
})
hideItemsReadFalse: function () {
var me = this,
items = me.getReferences().treelistRef.itemMap;
for(var i in items){
if(items[i].config.node.data.read == false){
items[i].destroy();
}
}
}
实际上,您询问了类的测试
“done”
。在这种情况下,只需测试this.attributes['cls']=='done'。我更喜欢检查“status”
而不是“cls”
,因为后者可能是空间分隔的,而且很混乱 例如,对于ExtJS 6,当read config为false时,隐藏节点:
tree.getRootNode().cascade(function() { // descends into child nodes
if(this.attributes['status'] == 100) { // test this node
this.getUI().hide() // hide this node
}
})
hideItemsReadFalse: function () {
var me = this,
items = me.getReferences().treelistRef.itemMap;
for(var i in items){
if(items[i].config.node.data.read == false){
items[i].destroy();
}
}
}
根目录:
{
"text": "root",
"children": [
{
"text": "Atualização",
"iconCls": "x-fa fa-list",
"children": [
{
"leaf":true,
"text": "Empresas",
"module": "empresas",
"iconCls": "x-fa fa-building",
"read": false
},
{
"leaf":true,
"text": "Produtos",
"module": "produtos",
"iconCls": "x-fa fa-cubes",
"read": true
}
]
}
]
}
在ExtJS4.1.3中对我不起作用。这样一个简单的需求,ExtJS没有。这就是为什么我讨厌Ext JS。