appendChild树节点不展开
appendChild tree node does not expand
本文关键字:树节点 appendChild 更新时间:2023-09-26
我有一个树面板,在初始加载时我在其中设置了一些根级节点。然后,当一个节点被打开时,我有一个javascript函数,在它下面添加子节点
我遇到了一个问题,无法使节点可扩展。它没有显示展开节点的箭头。
以下是我添加子节点的方法:
var onbeforeitemexpand = function(node, options) {
if (!node.hasChildNodes()) {
node.appendChild({
title:'Should not be expandable',
checked: false,
leaf:true
});
node.appendChild({
title:'Should expand',
checked: false,
leaf:false,
expandable:true
});
};
tree.on('beforeitemexpand', onbeforeitemexpand, null);
但第二个孩子是不可扩展的。我能让它扩展的唯一方法是像这样添加空的孩子:
node.appendChild({
title:'Should expand',
checked: false,
leaf:false,
expandable:true,
children:[{}]
});
但是它下面会有一个空节点,当我试图在这个节点下添加子节点时,当它被扩展时,子节点会进入空节点。
有没有更好的方法可以通过我自己的javascript函数(而不是通过ajax请求..)对树进行"延迟加载"?
无论我尝试了什么,当我通过函数向树中添加节点时,都无法获得指向节点的>箭头。我尝试了上述解决方案和自定义代理阅读器。。我终于接受了这个:
Ext.define('Ext.proxy.DocumentNodes', {
extend: 'Ext.data.proxy.Memory',
alias: 'proxy.documentnodes',
read: function(operation, callback, scope) {
var parent=operation.node;
var children=[];
children.push(
Ext.create('Document',{
title:'Some document',
iconCls:'task-folder',
checked: false,
leaf: false,
expandable: true,
children: [{tempitem: true}]
})
);
var result=Ext.create("Ext.data.ResultSet",{records: children});
Ext.apply(operation, {resultSet: result});
operation.setCompleted();
operation.setSuccessful();
Ext.callback(callback, scope || this, [operation]);
}
});
Ext.define('Document', {
extend: 'Ext.data.Model',
fields: [
{name: 'title', type: 'string'},
]
});
var store = Ext.create('Ext.data.TreeStore', {
model: 'Document',
proxy: {
type: 'documentnodes'
},
nextId: 1,
folderSort: false
});
然后将该存储用于树面板,并为树设置onbeforeitexpand监听器,如下所示:
var onbeforeitemexpand = function(node, options) {
var firstChild = node.getChildAt(0);
if (firstChild.get('tempitem')) {
node.removeChild(firstChild, true);
}
node.store.load({ node: node });
};
tree.on('checkchange', oncheckchange, null);
tree.on('beforeitemexpand', onbeforeitemexpand, null);
这一切的作用是,首先代理读取器创建节点,并在其下面添加一个空节点,这样>箭头就会出现在节点之前。然后在beforeitexpand中,它检查第一个节点是否是临时节点,并将其删除,并调用节点的重载,然后执行代理读取器,在已打开的节点下面添加新节点,并在其下面添加临时节点…
这看起来是一种非常愚蠢的方法,但它很有效,我不知道如果节点中没有任何子节点,但叶设置为false,可扩展设置为true,我怎么才能让>箭头出现在节点之前。
也许有人对此有更好的答案。
相关文章:
- 在不添加树节点的情况下从网格拖放到树
- 在带有 标记的树节点上以编程方式触发单击事件
- d3树节点位置
- 用于构建树节点层次结构的javascript库
- 树递归:如何获取所选树节点的父根
- 如何将 css 类添加到 Ext4 中的树节点
- 分页动态加载的 Webix 树节点
- D3.js具有相同父级的树节点
- 当我在 Dojo 中左键单击树行(树节点)时,如何从对象存储中获取 ID
- Dojo:使用 CSS 选择器识别 dijit 树节点
- 如何获取选择 JS 树节点时的祖先
- appendChild树节点不展开
- 从IE中的ASP.net树节点调用Jquery
- 在Ext.tree.TreePanel中,当我们加载树时,没有任何事件可以检查是否所有树节点都已完全加载
- 基于当前导航url的树节点选择
- 树节点以支持浏览器兼容性
- 是否有一种方法可以自动打开D3折叠树节点逐个节点(对于有子节点的节点)
- 我如何使用javascript添加树节点到树视图
- Infovis超树节点的需求
- 点击D3树节点