ExtJS - 将JSON数据加载到treepanel中

时间:2015-08-25 18:26:29

标签: javascript json extjs tree

我有树面板,它将显示所有节点的完整列表,而不是延迟加载格式。我首先发出一个ajax请求来获取一些普通数据,将其格式化为完整列表格式,然后我想将其附加到树中。

我的转换fn像这样返回JSON:

@

现在我要做的就是把这个JSON添加到treestore中。使用常规的Ext.data.Store,我可以简单地使用store.loadData()方法,但是对于treestore没有这样的方法。

我尝试使用上面的JSON传递的treeStore.setRootNode(),它会附加根节点,但不会附加任何子节点。

感谢。

1 个答案:

答案 0 :(得分:1)

方法就在那里。

load( [options] )

Loads the passed node (defaulting to the root node) using the configured proxy.

Be aware that it is not usually valid for a developer to call this method on a TreeStore.

TreeStore loads are triggered by a load request from an existing tree node, when the node is expanding, and it has no locally defined children in its data.
Parameters

    options : Object (optional)

    config object. This is passed into the Operation object that is created and then sent to the proxy's Ext.data.proxy.Proxy.read function. The options can also contain a node, which indicates which node is to be loaded. If not specified, it will default to the root node.
        node : Ext.data.NodeInterface (optional)

        The tree node to load. Defaults to the store's root node

Fires

    beforeload

Overrides: Ext.data.Store.load

http://docs.sencha.com/extjs/5.1/5.1.1-apidocs/#!/api/Ext.data.TreeStore-method-load