首页 > 解决方案 > 使用 JSON 值填充组合框

问题描述

我需要用 JSON 数据填充组合框。这是我的商店:

Ext.define('Test.store.GetShopSurvey', {
    extend: 'Ext.data.Store',

    alias: 'store.GetShopSurvey',

    model: 'Test.model.GetShopSurvey',

    storeId: 'GetShopSurvey',

    proxy: {
        type: 'ajax',
        url: 'http://localhost/webcontent/CShopSurveyWebApplet&SubFunc=GetShopSurvey',
        reader: {
            type: 'json',
        }
    }

});

而我的观点:

Ext.define('Test.view.main.Announcement',
{
    extend: 'Ext.panel.Panel',

    requires: [
        'Test.view.main.AnnouncementController',
        'Test.view.main.AnnouncementModel',
        'Test.store.Personnel'
    ],

    store: {
        type: 'GetShopSurvey'
    },

其中一项是:

{
    xtype: 'combo',
    fieldLabel: 'Range',
    name: 'Range1',
    store: , //here I need store to load. For example json value is {"range": 70}
    displayField: 'range',
    autoSelect: true,
    forceSelection: true,
    disabled: true
},

我使用名称和数据类型将字段添加到模型中。但是,我不知道如何从 JSON 中获取数据并在组合框中解析它。我评论了我需要放置该值的地方。

标签: extjs

解决方案


试试 loadRawData 方法

var jsonData = {'range':500};
combo.getStore().loadRawData(jsonData);

推荐阅读