我正在使用带有Json数据的Extjs4 treepanel。我想重新加载treepanel并需要将树菜单扩展到指定的节点。 我正在使用以下代码。请告诉我这是怎么回事。
//Define tree store
var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'my_tree.php',
},
noCache: false
});
// Treepanel
var treePanel = Ext.create('Ext.tree.Panel', {
id: 'mytree',
renderTo: 'tree_div',
height: 400,
bodyBorder: false,
border: false,
singleExpand: true,
rootVisible: false,
store: store,
useArrows: true
});
//Reload tree
function reload_tree(){
var tree_panel = Ext.getCmp('mytree');
tree_panel.enable();
tree_panel.getLoader().dataUrl = 'my_tree.php';
tree_panel.getLoader().load(tree_panel.root);
//Expand tree node
tree_panel.getLoader().on('load', function(loader, node){
tree_panel.getNodeById(nodeid).expand();
//here node id is tree menu nodeid
});
}
提前致谢
答案 0 :(得分:6)
重新加载树我觉得调用
更简单treePanel.getStore().load();
然后你可以听取load事件,这样就可以获取所有数据,最后从那里选择所需的节点。
treePanel.on("load", function( treeStore, records, successful, operation)){
var id = 4; // This is the ID of the node that somehow you know in advance
var node = treeStore.getNodeById(id);
treePanel.expandPath(node.getPath());
});
HTH!