0

我正在使用 ExtJs 4.1。我们有一个包含 JSON 格式数据的变量。我想将该 json 的值加载到我的 Ext.Data.TreeStore 中。通常商店有 loadData() 可以解决问题。但我没有看到 Ext.Data.TreeStore 有任何这样的方法。

如何将数据加载到 Ext.Data.TreeStore ?

以下是我的商店的定义。

Ext.define('my.store.HStore', {
    extend: 'Ext.data.TreeStore',
    model: 'my.model.myModel',
    autoLoad: false,
    proxy: {
        type: 'memory',
        timeout: 90000,
        url: '/data/',
        reader: {
            type: 'json'
        }
    }
});
4

1 回答 1

0

可能的重复:

如何在 TreePanel 中插入新记录(模型)?

如何使用 TreeStore 或 TreeEditor 组件更新数据?

回答

要在存储加载后将数据加载到 TreeStore,请按照此处的文档更新根节点:http ://docs.sencha.com/extjs/4.1.0/#!/api/Ext.data.TreeStore-方法-setRootNode

也相关并可能对您有所帮助:Treepanel with nested data from JSON

如果您希望将数据附加到 TreeStore,那么这有点复杂......您必须首先找到您希望将子节点附加到的节点(例如,store.getRootNode().findChildBy())并根据最适合的方式添加appendChildinsertChild节点你的用例。

findChildBy文档:http ://docs.sencha.com/extjs/4.1.0/#!/api/Ext.data.NodeInterface-method-findChildBy

appendChild文档:http ://docs.sencha.com/extjs/4.1.0/#!/api/Ext.data.NodeInterface-method-appendChild

insertChild文档:http ://docs.sencha.com/extjs/4.1.0/#!/api/Ext.data.NodeInterface-method-insertChild

PS: 我已经回答了你的一些问题,没有回应,接受或评论。请检查您提出的问题,我非常乐意回答它们,但是如果您接受您认为有帮助的答案,或者如果您需要更多信息,至少发表评论,这对整个社区最有利。谢谢你。

于 2013-09-03T13:53:40.920 回答