2012-09-11 60 views
-1

我是Sencha Touch2的新手,我試圖從一個簡單的商店加載任意數據開始我的應用程序,然後再繼續使用代理。我的觀點顯示,但數據沒有填充。我見過這個問題,但沒有任何幫助我解決的問題。任何幫助和耐心表示讚賞。多謝!無法從商店獲取我的數據以加載視圖

我的模型

Ext.define('SenchaFirstApp.model.Distributors', { 
     extend: 'Ext.data.Model', 
     config: { 
      fields: [ 
       {name: 't', type: 'string'}, 
       {name: 'distr', type: 'string'}, 
       {name: 'group', type: 'string'}, 
       {name: 'site', type: 'string'}, 
       {name: 'status', type: 'string'}, 
       {name: 'actuve', type: 'string'}, 
       {name: 'assigned', type: 'string'}, 
       {name: 'state', type: 'string'}, 
       {name: 'schedule', type: 'string'}, 
       {name: 'finished', type: 'string'} ], 
     } 
     }); 

我查看

var distrStore = Ext.create('SenchaFirstApp.store.DistributorStore'); 
Ext.define('SenchaFirstApp.view.DistributorView', { 
      extend: 'Ext.dataview.DataView', 
      requires: [distrStore, 'Ext.data.Store', 'Ext.dataview.List'], 
      model: 'SenchaFirstApp.model.Distributors', 
      xtype: 'mainlist', 
      fullscreen: true, 

     config: 
     { 
      fullscreen: true, 
      layout: 'fit', 
      border: 5, 
      title: 'Distributors', 
      html: 'My datalist', 
      autoLoad: true, 

      items:{ 
       title: 'Setup', 
       xtype:'list', 
       store: distrStore, 
       fields: [ 
        { 
         text: 'T', 
         width: 1, 
         sortable: false, 
         hideable: false, 
         dataIndex: 't' 
        }, 
        { 
         text: 'Distributor', 
         width: 50, 
         sortable: false, 
         hideable: false, 
         dataIndex: 'distr' 
        }, 
        { 
         text: 'Group', 
         width: 20, 
         sortable: false, 
         hideable: false, 
         dataIndex: 'group' 
        }, 
        { 
         text: 'Site Name', 
         width: 20, 
         sortable: false, 
         hideable: false, 
         dataIndex: 't' 
        }, 
        { 
         text: 'Status', 
         width: 5, 
         sortable: false, 
         hideable: false, 
         dataIndex: 'status' 
        }, 
        { 
         text: 'Active', 
         width: 5, 
         sortable: false, 
         hideable: false, 
         dataIndex: 'active' 
        }, 
        { 
         text: 'State', 
         width: 2, 
         sortable: false, 
         hideable: false, 
         dataIndex: 'state' 
        }, 
        { 
         text: 'Scheduled', 
         width: 10, 
         sortable: false, 
         hideable: false, 
         dataIndex: 'schedule' 
        }, 
        { 
         text: 'Finished', 
         width: 10, 
         sortable: false, 
         hideable: false, 
         dataIndex: 'finished' 
        } 
      ] 
        } 

     } 
}); 

distrStore.load();

我的商店

Ext.define('SenchaFirstApp.store.DistributorStore', { 
         extend: 'Ext.data.Store', 
         requires: ['SenchaFirstApp.model.Distributors', 'Ext.dataview.DataView'], 

         config: { 
         // xtype: 'distrlist', 
          storeId: 'mainlist', 
         model: 'SenchaFirstApp.model.Distributors', 
         autoLoad: true, 
         data: [ 
           {t: 'S', distr: 'Smart Systems', site: 'Smart Temps', status: "done", active: 'Yes', assigned: 'Me', state: 'IN',                  schedule: 'today', finished: 'today'}, 
           {t: 'I', distr: 'People', site: 'This One', status: "done", active: 'Yes', assigned: 'You', state: 'NC', schedule:             'yesterday', finished: 'tomorrow'} 
           ]}}); 

app.js

Ext.Loader.setConfig({enabled:true}); 
Ext.application({ 
    name: 'SenchaFirstApp', 
    stores: ['DistributorStore'], 
    models: ['Distributors'], 
    views: ['DistributorView'], 
    requires: ['SenchaFirstApp.view.DistributorView', 'Ext.dataview.DataView', 'SenchaFirstApp.model.Distributors', 'SenchaFirstApp.store.DistributorStore', 'Ext.dataview.List'], 

launch: function() {  
    Ext.fly('appLoadingIndicator'); 
    Ext.Viewport.add(Ext.create('SenchaFirstApp.view.DistributorView')); 
    } 

});

回答

2

你並不需要創建您的商店的一個實例:

var distrStore = Ext.create('SenchaFirstApp.store.DistributorStore'); 

當您在應用程序中定義您的商店因爲......

Ext.application({ 
    stores: ['DistributorStore'], 
    ... 
}); 

...它是自動創建您。爲了讓您的視圖您的商店的參考,只需使用一個字符串名稱:

{ 
    xtype: 'list', 
    store: 'DistributorStore', 
    ... 
} 

其他說明

  • 你也不需要使用​​它加載,因爲你已經設置autoLoad在您的商店配置中爲true。
  • 您的觀點應該延伸Ext.Container而不是Ext.dataview.DataView。 DataView用於顯示數據(基本上是一個抽象的Ext.List。因爲你有一個列表作爲一個項目,所以你可以把它放在一個容器裏面
  • 你已經在類和配置中設置了fullscreen: true。將其放入配置中 - 但它並不是真正必要的,因爲您正在創建視圖並將其插入Ext.Viewport(在您的app.js中),該視圖已經全屏顯示。
  • 您不需要fields配置在您的列表中。一個itemTpl爲每一行創建模板
+0

感謝您的詳細回覆,它幫助我清除了一些問題。但是,我提出了所有建議的更改,並且我的數據仍然沒有顯示,並且分隔兩行的行現在已經消失。你能看到我仍然缺少的東西嗎?再次感謝。我很感激幫助。我一直無法找到一個可行的示例,因此我將不同的示例關聯在一起,這可能不是很好:/ – codeMagic

+0

我用我的storeId('mainlist')引用了我的商店我的看法和我得到了我的分隔線,沒有錯誤,但仍然沒有數據。 – codeMagic

+0

終於!出於某種原因,我將配置佈局更改爲「vbox」,但我沒有意識到我已經完成了這項工作。一旦我將它改回「適合」。這是工作。現在我有一些嚴重的格式問題,但我現在有數據可以使用。再次感謝你的幫助! – codeMagic