我发现我无法删除尚未渲染的节点。下面的代码说明了我的意思。我在http://dev.sencha.com/deploy/dev/exa...dow/hello.html上从 Chrome(和 Firebug)的命令行运行它(因为该页面已预加载 ext)
我分别输入了每个语句以确保异步操作没有问题(即使树数据在内存中)
Ext.getBody.update('');
// Tree with preloaded nodes in memory
var tree = new Ext.tree.TreePanel({
renderTo: Ext.getBody(),
width: 300,
height: 500,
rootVisible: false,
loader: new Ext.tree.TreeLoader({preloadChildren:true}),
root: new Ext.tree.AsyncTreeNode({
expandend: true,
children: [
{text: 'Folder 1', id: 'folder1', leaf: false, children: [
{text: 'File 1', id: 'file1', leaf: true},
{text: 'File 2', id: 'file2', leaf: true}
]}
]
})
});
// Try to delete 'File 1', notice that the folder has never been expanded
tree.getRootNode().childNodes[0].childNodes[0].remove(true);
// Expand the node and see that 'File 1' is still there
tree.getRootNode().childNodes[0].expand();
// Delete the first child 1 again, it works now that it's been rendered
tree.getRootNode().childNodes[0].childNodes[0].remove(true);
关于做什么的任何建议?
回答
var nodeToRemove = tree.getRootNode().childNodes[0].childNodes[0];
if (!nodeToRemove.rendered) {
var children = node.parentNode.attributes.children;
Ext.each(children, function(child, index){
if (child.id == nodeToRemove.id) {
chilren.splice(index, 1);
return false;
}
}) ;
} else {
nodeToRemove.remove(true);
}