主要任务是在加载树面板后使用ajax动态打开一个分支。用户不应进行任何点击。它应该在页面加载后自行展开。
我尝试使用 afterrender 事件递归加载节点。但我无法在那里获取当前的树对象。这一步是空的。
这就像expandAll调用。此代码也不适用于渲染后事件:
tree.expandAll(function() {
tree.getEl().unmask();
toolbar.enable();
});
那么,如何使用ajax加载节点?
更新1: 上面的代码现在可以工作了。我只是在“树”定义之后添加此代码。 但问题仍然在这里。如何使用ajax加载一个节点?
最佳答案
你不能像大多数例子一样使用树存储吗?如果这样做,树将自动从存储请求节点,并且存储将从服务器加载内容。假设您的服务器代码可以发送回给定特定节点的分支。
See the Sencha Kitchen Sink demos of a tree working against the server with a TreeStore.
如果您在 Chrome 中打开开发人员工具,转到“网络”选项卡,然后伸展树(Splay Tree)中的一个节点,您将看到 TreeStore 将通过从“get-nodes.php”请求数据来自动加载该节点的子节点给定已展开的节点的 id。
您可以通过简单地调用 .expand()
来扩展节点。
如果这不起作用,您可以加载模型,当您拥有它时,将其添加到树中并展开父级,如下所示:
MyApp.model.MyTreeModel.load(someId, {
success: function (record, operation) {
// If the third param is true the search will be recursive from the supplied node
var node = tree.getRootNode().findChild('id', someParentId, true);
node.addChild(record);
node.expand();
},
scope: this
});
您的问题有点宽泛,所以我希望这对您有所帮助。
您可能想看看 Ext.data.NodeInterface documentation about how to manipulate trees.
关于javascript - ext js 树 : How load nodes dynamically when afterrender event occured?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15606116/