我正在寻找一种递归扩展树节点的方式。树没有被装载到最大。我们一次只加载一个深度级别。因此,例如,如果我的路径有3个深度级别(/ nodeId1/nodeId14/nodeId142),我想加载第一个节点,然后通过我路径中的第二个ID(在这种情况下为nodeId14)将第2级节点展开,然后得到第三等ExtJS递归扩展树节点
然而,当一个节点展开时,代理有一个AJAX调用来获取节点的孩子的数据,并且由于这个调用是异步的,程序本身试图向前移动下一级节点,在请求有时间完成之前给我一个“节点未定义错误”,因为级别2尚未加载。
我一直在寻找1天现在如何解决这个问题,但没有任何帮助。我发现了一个解决同样问题的博客,但帖子是从2009年开始的,他使用的一些东西已经过时。
http://hamisageek.blogspot.gr/2009/04/extjs-tip-recusively-opening-nodes-in.html
一些代码,以帮助:
Ext.define('treeStore',
{
extend : 'Ext.data.TreeStore',
alias: 'widget.treeStore',
autoLoad : false,
model : 'treeModel',
root : {
id: 0,
name : 'Root',
expanded : true,
loaded: true
},
proxy : {
type : 'ajax',
url : 'MyServlet',
reader : {
type : 'json',
root : 'children'
}
},
folderSort: true
});
Ext.define('Ext.tree.Panel',{
.
.
.
//Stuff about the tree panel etc.
dockedItems: {
xtype: 'textfield',
name: 'Search',
allowBlank: true,
enableKeys: true,
listeners: {
specialkey: function (txtField, e) {
if (e.getKey() == e.ENTER){
var searchValue = txtField.getValue();
Ext.Ajax.request({
url: 'MyServlet',
params: {
caseType: 'search',
value: searchValue
},
success: function(response) { //ATTENTION: When calling the .expand() the AJAX hasn't finished and cannot find the node.
response = Ext.decode(response.responseText);
var panel = txtField.up();
response.IDs.forEach(function(entry){
panel.getStore().getNodeById(entry.folderId).expand(); <-problem here
});
}
});
}
}
}
}
我已经尝试添加功能展开()回调,我已经试过DelayedTask的,我试过的SetTimer等,但没有作品。我真的没有选择,这似乎是这样一个简单的事情,但它使我发疯。