简体   繁体   English

将数据加载到Ext.Data.TreeStore

[英]Loading data into Ext.Data.TreeStore

I am using ExtJs 4.1. 我正在使用ExtJs 4.1。 We have one variable which contains data in JSON format. 我们有一个变量,它包含JSON格式的数据。 I want to load the value of that json into my Ext.Data.TreeStore. 我想将该json的值加载到Ext.Data.TreeStore中。 Usually store have loadData() which does the trick. 通常存储有loadData()这个技巧。 But I do not see any such method for Ext.Data.TreeStore. 但是我没有看到Ext.Data.TreeStore这样的方法。

How can I load data into Ext.Data.TreeStore ? 如何将数据加载到Ext.Data.TreeStore中?

Below is the definition of my store. 以下是我的商店的定义。

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'
        }
    }
});

Possible duplicates: 可能重复:

How to insert new record ( model ) in TreePanel? 如何在TreePanel中插入新记录(模型)?

How to update data with TreeStore or TreeEditor component? 如何使用TreeStore或TreeEditor组件更新数据?

Answer 回答

To load data into a TreeStore after the store has loaded, you update the root node as per the documentation here: http://docs.sencha.com/extjs/4.1.0/#!/api/Ext.data.TreeStore-method-setRootNode 要在存储加载后将数据加载到TreeStore中,请根据此处的文档更新根节点: http ://docs.sencha.com/extjs/4.1.0/#!/api/Ext.data.TreeStore- method-setRootNode

Also relevant and may help you: Treepanel with nested data from JSON 同样相关,可能对您帮助: Treepanel中包含来自JSON的嵌套数据

If you wish to append data to a TreeStore, well that is a bit more complicated... You must first locate the node that you wish to append a child to (eg, store.getRootNode().findChildBy() ) and add the child by either appendChild or insertChild depending on what best suits your use case. 如果您希望将数据追加到TreeStore,那就有点复杂了……您必须首先找到要向其追加子项的节点(例如store.getRootNode().findChildBy() )并添加child由appendChildinsertChild具体取决于最适合您的用例的情况。

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

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

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

PS: I have answered a few of your questions with no response, acceptance or comments. PS:我已经回答了您的一些问题,但没有任何回应,接受或评论。 Please check the questions that you have asked, I'm more than happy to answer them however it is most beneficial to the entire community if you accept answers that you find helpful, or at least leave a comment if you need additional information. 请检查您所提出的问题,我很乐意为您解答,但是如果您接受对您有帮助的答案,则对整个社区都是最有益的;如果您需要其他信息,请至少留下评论。 Thank you. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM