如何用包含数组的JSON对象填充ExtJS组合框?

问题描述 投票:1回答:2

我有以下JSON,从后端接收它:

{
    "scripts": [
        "actions/rss",
        "actions/db/initDb",
        "actions/utils/MyFile",
        "actions/utils/Valid"
    ],
    "success": true
}

JSON存储:

    this.store = new Ext.data.JsonStore({

        proxy: new Ext.data.HttpProxy({
            url: "http://www.example.com",
            method: 'POST'
        }),
        baseParams: {
            appId: "hsvdvndcnwvwbasxcwyc"               
        },
        root: 'scripts',
        fields: ['value']

    });

组合框:

    this.aField = new Ext.form.ComboBox({
        fieldLabel      : 'action',
        name        : 'actionName',
        anchor      : "95%",                     
        allowBlank      : false,
        emptyText       : "Select action",            

    triggerAction   : 'all',
    lazyRender      : true,
    mode            : 'remote',
        store           : this.store,
    valueField      : 'value',
    displayField    : 'value'
    });     

所以,我收到来自后端的响应,没关系。但是我的组合框下拉列表为空(它显示10个空行,它们等于JSON中的项目数)。我知道这个问题在JSON Store的fields属性中。但是我应该放在那里什么才能使其正常工作?

谢谢!

javascript ajax json extjs extjs3
2个回答
1
投票

尝试在根读取器对象中添加根目录:'scripts来修改“ JSON存储:”代码,也添加类型并在代理中添加读取器。

因此,JSON存储:代码应如下所示

this.store = new Ext.data.JsonStore({
   proxy: new Ext.data.HttpProxy({
        url: "http://www.example.com",
        method: 'POST',
        reader: {            
                  type:'json',
                  root: 'scripts'
        }
    }),
    baseParams: {
        appId: "hsvdvndcnwvwbasxcwyc"               
    },

    fields: ['value']
});

0
投票

这对我有所帮助,但是...

© www.soinside.com 2019 - 2024. All rights reserved.