2012-03-16 23 views
5

我無法獲得實際數據顯示在Sencha Touch 2列表中。該列表應該由JSONP響應填充,我期望顯示2行。相反,我得到了'null null'的一行。Sencha Touch 2 - JSONP代理幫助,模板的值始終爲空

這裏是一個被髮送的網址:

http://some-server/data-fetcher.php?_dc=1331910031292&events=true&page=1&start=0 
    &limit=25&callback=Ext.data.JsonP.callback1 

這裏的JSONP響應:

Ext.data.JsonP.callback1({"data":[{"id":"4","name":"Sample Name 1", 
    "description":null,"location":"Sample Location 1", 
    "start_time":"2012-03-22 00:00:00","end_time":null},{"id":"5", 
    "name":"Sample Name 2","description":null,"location":"Sample Location 2", 
    "start_time":"2012-03-31 00:00:00","end_time":null}],"num_rows":2}); 

這裏是我的模型:

Ext.define('MyApp.model.Event', { 
    extend: 'Ext.data.Model', 
    config : { 
     idProperty: 'id', 
     fields : [ { 
      name : "id", 
      type : "int" 
     }, { 
      name : "name", 
      type : "string" 
     }, { 
      name : "description", 
      type : "string" 
     }, { 
      name : "location", 
      type : "string" 
     }, { 
      name : "start_time", 
      type : "date" 
     }, { 
      name : "end_time", 
      type : "date" 
     } ] 
    } 
}); 

這裏是我的店:

Ext.define('MyApp.store.EventsOnline', { 
    extend : 'Ext.data.Store', 
    requires: ['MyApp.model.Event'], 
    config : { 
     model : 'MyApp.model.Event', 
     autoLoad : true, 
     proxy : { 
      type : 'jsonp', 
      url : 'http://some-server/data-fetcher.php', 
      reader : { 
       type : 'json', 
       root : 'data', 
       totalCount : 'num_rows' 
      }, 
      callbackKey : 'callback', 
      extraParams : { 
       'events' : true 
      } 
     } 
    } 
}); 

這是我的觀點:

Ext.define('MyApp.view.Event', { 
    extend: 'Ext.Container', 
    config : { 
     layout : { 
      type : 'vbox', 
      align : 'stretch' 
     }, 
     fullscreen : true, 
     flex : 1, 
     items : [ 
      { 
       xtype : 'toolbar', 
       docked : 'top', 
       title : 'Events' 
      }, { 
       xtype : 'list', 
       flex : 1, 
       store : 'EventsOnline', 
       itemTpl : '{name} at {location}' 
      } 
     ] 
    } 
}); 

我希望我的列表中看到的是:

Sample Name 1 at Sample Location 1 
Sample Name 2 at Sample Location 2 

,而是所有我看到的是:

null at null 

我在做什麼錯?

編輯:如果它很重要,這裏有我的應用程序和控制器:

Ext.Loader.setConfig({enabled : true}); 

Ext.application({ 
    name    : 'MyApp', 
    appFolder   : 'app', 
    controllers : ['Home'], 
    launch : function() { 
     window[this.getName()].app = this; 
    } 
}); 

Ext.define('MyApp.controller.Home', { 
    extend: 'Ext.app.Controller', 
    models: ['Event'], 
    stores: ['EventsOnline'], 
    views: ['Event'], 
    init: function() { 
     var me = this; 
     Ext.Viewport.add(Ext.create('MyApp.view.Event')); 
    } 
}); 

回答

3
root : 'data', 
totalCount : 'num_rows' 

已被棄用。用途:

rootProperty: 'data', 
totalProperty: 'num_rows' 

sencha-touch-all-compat.js請確保您已經煎茶觸摸的發展。它會在瀏覽器控制檯中報告您使用的所有棄用事項。

+0

Arrrrgh,就是這樣。在這一整天我敲着頭之後,我終於轉向了jQuery Mobile,看看我是否會有更好的運氣。呃,也許我現在會回到Sencha Touch 2。對他們來說,「棄用」意味着「完全取出」似乎是蹩腳的。我在網上發現了很多Sencha Touch教程,現在不適用,因爲v2已被棄用/刪除了很多。 – 2012-03-16 19:25:01

+1

浪費了一天,謝謝。向後兼容! – SteveCav 2012-03-27 00:09:13