1

我在向组合框添加数据时遇到问题(这是我的代码:

{
    xtype: 'combo',
    name: 'accounttype',
    triggerAction: 'all',
    fieldLabel: '??? ?????',
    labelWidth: 125,
    displayField: 'name_y',
    valueField: 'nzp_y',
    width: 280,
    emptyText: '??? ?????',
    listeners: {
        afterrender: function (item) {
            Ext.Ajax.request({
                url: 'account/combodata',
                method: 'POST',
                success: function (objServerResponse) {
                    var jsonResp = Ext.decode(objServerResponse.responseText);


                if (jsonResp.success == true) {

                    var mystore = new Ext.data.JsonStore({
                        fields: ['nzp_y', 'name_y'],
                        data: [{ nzp_y: 0, name_y: ' '}]
                    });

                    var myArray = new Array();

                    for (var i = 0; i < jsonResp.combolist.length; i++) 
                    {
                        if (jsonResp.combolist[i].nzp_res == 9999) 
                        {
                            myArray['nzp_y'] = jsonResp.combolist[i].nzp_y;
                            myArray['name_y'] = jsonResp.combolist[i].name_y;
                            //???
                        }
                    }
                }
            },
            failure: function (objServerResponse) {
                Ext.Msg.alert('Error', objServerResponse.responseText);
            }
        });
    }
},
store: mystore

}

如何将商店添加到组合?谢谢。

4

1 回答 1

1

假设您使用的是 ExtJS 4.x

我推荐你使用 Model-Proxy-Store

 // Set up a model to use in your Store
 Ext.define('User', {
     extend: 'Ext.data.Model',
     fields: [
         {name: 'nzp_y', type: 'int'},
         {name: 'name_y',  type: 'string'}
     ]
 });

...一些其他代码

{
    xtype: 'combo',
    name: 'accounttype',
    triggerAction: 'all',
    fieldLabel: '??? ?????',
    labelWidth: 125,
    displayField: 'name_y',
    valueField: 'nzp_y',
    width: 280,
    store: Ext.create('Ext.data.Store', {
         model: 'User',
         proxy: {
             type: 'ajax',
             url: '/account/combodata',
             reader: {
                 type: 'json',
                 root: 'data' // you may need to modify this
             }
         },
         autoLoad: true
     }),
    emptyText: '??? ?????'
}

编辑以回答评论:

您绝对应该查看以下配置(可以在下面添加root: 'data'):

idProperty     : 'id'  // You seem not to have a id property based on the given values
totalProperty  : 'total' // You don't have this one at all

请先检查这些并发布结果。对于给定的错误,我有这样的想法。没见过这个。

于 2012-09-06T06:16:42.227 回答