2011-04-21 93 views
2

我的JsonStore似乎沒有填充。當我運行代碼時,它會關閉請求,並返回json。當我檢查數據存儲時,數據數組是空的。ExtJS JsonStore未填充

我缺少什麼?謝謝。

我有這個JsonStore定義:

CCList.ListStore = new Ext.data.JsonStore({ 
    root: 'rows', 
    idProperty: 'Id', 
    fields: ['Id', 'Description'], 
    autoLoad: true, 
    proxy: new Ext.data.HttpProxy({ 
     method: 'GET', 
     url: '/costcenters/getjson' 
    }), 
    listeners: { 
     load: function (obj, records) { 
      Ext.each(records, function (rec) { 
       console.log(rec.get('Id')); 
      }); 
     } 
    } 
}); 

試圖把它這個JSON綁定到這個Ext.List

CCList.listPanel = new Ext.List({ 
      id: 'indexList', 
      store: CCList.ListStore, 
      itemTpl: '<div class="costcenter">{Id}-{Description}</div>' 
      } 
     }); 

我的網址回報:

{ "rows" : [ 
     { "Description" : "Jason", 
     "Id" : "100" 
     }, 
     { "Description" : "Andrew", 
     "Id" : "200" 
     }   
    ] } 

回答

2

FYI你不使用ExtJS,你使用的是Sencha Touch,它們是不同的,因此今後澄清這一點很重要。

Ext.setup({ 
    onReady: function(){ 
     Ext.regModel('CostCenter', { 
      idProperty: 'Id', 
      fields: ['Id', 'Description'] 
     }); 

     var store = new Ext.data.Store({ 
      model: 'CostCenter', 
      autoLoad: true, 
      proxy: { 
       type: 'ajax', 
       method: 'GET', 
       url: 'data.json', 
       reader: { 
        type: 'json', 
        root: 'rows' 
       } 
      }, 
      listeners: { 
       load: function(obj, records){ 
        Ext.each(records, function(rec){ 
         console.log(rec.get('Id')); 
        }); 
       } 
      } 
     }); 

     new Ext.List({ 
      fullscreen: true, 
      store: store, 
      itemTpl: '<div class="costcenter">{Id}-{Description}</div>' 
     }); 

    } 
}); 
+0

非常感謝您。 JsonStore也不適用於Sencha Touch嗎? – 2011-04-22 03:05:54

+0

它就在那裏,但數據包的工作方式現在有點多餘,你最好堅持我上面概述的方法。 – 2011-04-22 03:27:06