【问题标题】:Laoding JSON data into Ext.data.Tree store on click on a button单击按钮将 JSON 数据加载到 Ext.data.Treestore
【发布时间】:2013-12-21 19:42:03
【问题描述】:

我在 ExtJs 4.1 中创建了一个树面板,该面板与 store 相关联。我在变量中有一些可用的 JSON 数据。如何通过单击按钮将其加载到树存储中。

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'id',    type: 'int'},
        {name: 'name',  type: 'string'},
        {name: 'phone', type: 'string', mapping: 'phoneNumber'}
    ]
});


var data = {
    users: [
        {
            id: 1,
            name: 'Ed Spencer',
            phoneNumber: '555 1234'
        },
        {
            id: 2,
            name: 'Abe Elias',
            phoneNumber: '666 1234'
        }
    ]
};

//注意我们如何在阅读器中设置'root'来匹配上面的数据结构

var store = Ext.create('Ext.data.TreeStore', {
    autoLoad: false,
    model: 'User',
    proxy: {
        type: 'memory',

    }
});

如何在点击按钮时加载数据?

【问题讨论】:

  • 代码你试过了吗?

标签: javascript json extjs extjs-stores


【解决方案1】:
var store = Ext.create('Ext.data.TreeStore', {
    model: yourModel, // make sure the model fits
    proxy: {
        data : yourData, // this is your var with json
        type: 'memory',
        reader: {
            type: 'json'
        }
    },
});

在这里查看答案:Load static data to Ext.data.TreeStore

要在按钮点击上运行您的代码,请执行以下操作:

Ext.create('Ext.Button', {
    text: 'Click me',
    handler: function() {
        // load the store
    }
});

【讨论】:

    【解决方案2】:

    试试store.data = data,好像没有'setData'之类的方法,试试store.data = data也许会行

    【讨论】:

      【解决方案3】:

      您可以在按钮单击时使用 store.loadData 方法。检查文档here

      【讨论】:

      • 这是一棵要加载的树。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-07
      • 1970-01-01
      相关资源
      最近更新 更多