2012-03-16 7 views
5

Ho problemi a visualizzare i dati attuali in un elenco Sencha Touch 2. L'elenco dovrebbe essere compilato da una risposta JSONP e mi aspetto che vengano visualizzate 2 righe. Invece, ottengo una riga con "null at null".Sencha Touch 2 - Guida proxy JSONP, il modello ha sempre valori null per i valori

Ecco l'URL che viene inviato:

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

Ecco la risposta 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}); 

Ecco il mio modello:

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" 
     } ] 
    } 
}); 

Ecco il mio negozio:

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 
      } 
     } 
    } 
}); 

Ecco mio punto di vista:

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}' 
      } 
     ] 
    } 
}); 

Quello che mi aspetto di vedere nella mia lista è:

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

E invece tutto quello che vedo è:

null at null 

Che cosa sto facendo di sbagliato ?

Edit: se è importante, qui ci sono la mia app e il controller:

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')); 
    } 
}); 

risposta

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

è deprecato. Usa:

rootProperty: 'data', 
totalProperty: 'num_rows' 

Assicurarsi di incluso Sencha Touch di sencha-touch-all-compat.js per lo sviluppo. Riporterà nella console del browser tutte le cose deprecate che usi.

+0

Arrrrgh, era così. Dopo avermi sbattuto la testa per tutto il giorno, sono finalmente passato a jQuery Mobile, per vedere se avrei avuto più fortuna. Sheesh, forse tornerò su Sencha Touch 2 ora. Sembra zoppo che "deprecato" per loro significhi "tolto completamente". Trovo online così tante esercitazioni Sencha Touch che non si applicano ora perché la v2 è stata deprecata/rimossa molto. –

+1

Ho sprecato un giorno in questo, grazie. Torna alla compatibiltà! – SteveCav

0

Ho anche faticato a visualizzare la mia lista e cercare molto su questo.

finalmente ottenuto la mia risposta dopo aver cambiato questo a mio avviso:

extend: 'Ext.Container', 

a

extend:'Ext.navigation.View', 

ho avuto l'idea di sopra dal link esempio qui sotto!

Sencha Touch 2: data intigration or how to share dynamic information between sencha and javascript

E ora lavorando, felice di vedere il mio primo esempio MVC lavoro :)

La speranza è aiutare qualcuno.