2013-12-18 49 views
0

我無法分辨爲什麼我的商店不綁定從服務器返回的數據。先謝謝你。爲什麼我的商店即使返回數據也不會加載數據

這是我如何實例化和調用 「加載」:

var store = Ext.create('Iip.store.giip.other.States'); 
store.load({ 
    params: {c: 'get_states'}, 
    scope: this, 
    callback: function(records, operation, success) { 
     console.log(records); **<=== never prints** 
    } 
}); 

這裏是商店:

Ext.define("Iip.store.giip.other.States", { 
    extend: "Ext.data.Store", 
    storeId:"states-store", 
    model: "Iip.model.giip.other.State", 
    autoLoad: false, 
    buffered: true 
}); 

這裏是模型:

Ext.define('Iip.model.giip.other.State', { 
    extend: 'Ext.data.Model', 
    idProperty: "stateId", 

    fields:[ 
     {name: "stateId", type: "int"}, 
     {name: "state", type: "string"} 
    ], 

    proxy: { 
     type: "ajax", 
     actionMethods: { 
      read: "POST" 
     }, 
     api: { 
      read: "indexes/common_index.php" 
     }, 
     reader: { 
      type: "json", 
      root: "states" 
     }, 
     listeners: { 
      exception: function(proxy, response, operation, opts) { 
       if(typeof(operation.error) == "string") { 
        Ext.Msg.alert("Error", "Connection to server interrupted"); 
       } 
      } 
     } 
    } 
}); 

這裏是數據從螢幕上的服務器返回:

{"states":[{"stateId":"1","state":"AL"},{"stateId":"2","state":"AK"}, 
{"stateId":"3","state":"AS"},{"stateId":"4","state":"AZ"},{"stateId":"5","state":"AR"},   
{"stateId":"6","state":"CA"},{"stateId":"7","state":"CO"},{"stateId":"8","state":"CT"}, 
{"stateId":"9","state":"DE"},{"stateId":"10","state":"DC"}, 
{"stateId":"11","state":"FM"},{"stateId":"12","state":"FL"}, 
{"stateId":"13","state":"GA"},{"stateId":"14","state":"GU"}, 
{"stateId":"15","state":"HI"},{"stateId":"16","state":"ID"}, 
{"stateId":"17","state":"IL"},{"stateId":"18","state":"IN"}, 
{"stateId":"19","state":"IA"},{"stateId":"20","state":"KS"}, 
{"stateId":"21","state":"KY"},{"stateId":"22","state":"LA"}, 
{"stateId":"23","state":"ME"},{"stateId":"24","state":"MH"}, 
{"stateId":"25","state":"MD"},{"stateId":"26","state":"MA"}, 
{"stateId":"27","state":"MI"},{"stateId":"28","state":"MN"}, 
{"stateId":"29","state":"MS"},{"stateId":"30","state":"MO"}, 
{"stateId":"31","state":"MT"},{"stateId":"32","state":"NE"}, 
{"stateId":"33","state":"NV"},{"stateId":"34","state":"NH"}, 
{"stateId":"35","state":"NJ"},{"stateId":"36","state":"NM"}, 
{"stateId":"37","state":"NY"},{"stateId":"38","state":"NC"}, 
{"stateId":"39","state":"ND"},{"stateId":"40","state":"MP"}, 
{"stateId":"41","state":"OH"},{"stateId":"42","state":"OK"}, 
{"stateId":"43","state":"OR"},{"stateId":"44","state":"PW"}, 
{"stateId":"45","state":"PA"},{"stateId":"46","state":"PR"}, 
{"stateId":"47","state":"RI"},{"stateId":"48","state":"SC"}, 
{"stateId":"49","state":"SD"},{"stateId":"50","state":"TN"}, 
{"stateId":"51","state":"TX"},{"stateId":"52","state":"UT"}, 
{"stateId":"53","state":"VT"},{"stateId":"54","state":"VA"}, 
{"stateId":"55","state":"VI"},{"stateId":"56","state":"WA"}, 
{"stateId":"57","state":"WV"},{"stateId":"58","state":"WI"}, 
{"stateId":"59","state":"WY"}]} 

下面是數據應該綁定到組合:變更後

{ 
           xtype: 'combo', 
           fieldLabel: 'State', 
           store: store, 
           displayField: 'state', 
           valueField: 'stateId', 
           anchor:'97%', 
           itemId: 'fatherState', 
           editable: false, 
           allowBlank: false, 
           emptyText: 'Select a state', 
           tabIndex: 6, 
           queryMode: 'local' 
          } 
+0

存儲加載是異步的,由th當你記錄計數時,它還沒有從服務器返回。 –

+0

但記錄回調中的記錄呢?那裏它應該打印記錄數 –

+0

console.log(記錄)從不打印任何東西。這讓我感到困惑。 –

回答

0

試試這個兩個fiels像下面

店:

Ext.define("Iip.store.giip.other.States", { 
     extend: "Ext.data.Store", 
     config: { 
      storeId:"states-store", 
      model: "Iip.model.giip.other.State", 
      autoLoad: false, 
      buffered: true, 
      proxy: { 
       type: "ajax", 
       actionMethods: { 
        read: "POST" 
       }, 
      api: { 
       read: "indexes/common_index.php" 
       }, 
       reader: { 
       type: "json", 
       root: "states" 
      }, 
      listeners: { 
       exception: function(proxy, response, operation, opts) { 
       if(typeof(operation.error) == "string") { 
         Ext.Msg.alert("Error", "Connection to server interrupted"); 
       } 
      } 
      } 
     } 
     } 

    }); 

型號:

Ext.define('Iip.model.giip.other.State', { 
      extend: 'Ext.data.Model', 
      idProperty: "stateId", 

      fields:[ 
      {name: "stateId", type: "int"}, 
      {name: "state", type: "string"} 
      ] 


    }); 
+0

我嘗試了將代理放入商店的建議,但我的組合仍然沒有狀態。 –

+0

我也試過這個。我只是創建一個商店沒有加載並分配給組合。組合渲染後,我加載。但是,回調函數再次不會被調用。這讓我瘋狂。我即將結束的事情,我可以嘗試。 –

+0

這裏是我試圖在我以前的留言中提到的代碼:'聽衆:{ \t \t AfterRender階段:)函數({ \t \t \t變種狀態= Ext.ComponentQuery.query( '#fatherState')[0]; \t \t \t state.getStore()負載({ \t \t \t \t PARAMS:{C: 'get_states'}, \t \t \t \t回調:功能(記錄,ST,SUC){ \t \t \t \t \t console.log(records); \t \t \t \t \t console.log(state.getStore()。getTotalCount()); \t \t \t \t} \t \t \t}); \t \t} \t},' –

相關問題