首页 文章

ext js tree:Afterrender事件发生时如何动态加载节点?

提问于
浏览
1

主要任务是在加载树面板后使用ajax打开一个分支 . 用户不应该进行任何点击 . 它应该在页面加载后展开 .

我试图使用afterrender事件递归加载节点 . 但我无法获得当前的树对象 . 在这一步它是空的 .

就像expandAll调用一样 . 此代码也不适用于Afterrender事件:

tree.expandAll(function() {
     tree.getEl().unmask();
    toolbar.enable();
  });

那么,我如何使用ajax加载节点?

UPDATE 1: 上面的代码现在正在运行 . 我只是在"tree"定义后添加此代码 . 但问题仍然存在 . 如何使用ajax加载一个节点?

1 回答

  • 0

    你不能像大多数例子一样使用树店吗?如果这样做,树将自动从商店请求节点,商店将从服务器加载东西 . 鉴于您的服务器代码可以发送给定特定节点的分支 .

    See the Sencha Kitchen Sink demos of a tree working against the server with a TreeStore.

    如果您在Chrome中打开开发人员工具,请转到网络选项卡,然后在树中展开一个节点,您将看到TreeStore将通过在给定id的情况下从“get-nodes.php”请求数据来自动加载该节点的子节点扩展的节点

    您只需在其上调用 .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.

相关问题