2012-09-06 39 views
2

我有一個數據添加到組合框的一個問題連擊(這是我的代碼:添加數據ExtJS的

{ 
    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 

}

我如何添加店連擊 感謝

回答

1

假設您使用的是ExtJS 4.x

我建議您使用Mode 1-代理商店

// 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: '??? ?????' 
} 

編輯回答評論:

你definetely應該看看下面CONFIGS(可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 

請先檢查並公佈結果。對於給定的錯誤,我有這麼想法。從來沒有見過這個。

+0

我回答了我的請求: {「success」:true,「message」:null,「list」:null,「data」:[{「name_y」:「???」,「nzp_res」: 18, 「nzp_y」:1},{ 「name_y」: 「???」, 「nzp_res」:18, 「nzp_y」:2},{ 「name_y」: 「???」, 「nzp_res」:18, 「nzp_y」:3},{ 「name_y」: 「???」, 「nzp_res」:9999, 「nzp_y」:1},{ 「name_y」: 「???」, 「nzp_res」:9999,「nzp_y 「:2」,{「name_y」:「???」,「nzp_res」:9999,「nzp_y」:3}]} 我試過你的建議,但它給了我錯誤(reader.read不是 函數)在這一行中: result = reader.read(me.extractResponseData(response)); – Oleg