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

应用程序.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'));
    }   

});

4

1 回答 1

2

您不需要创建商店的实例:

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

因为当您在应用程序中定义商店时...

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

...它是自动为您创建的。要在您的视图中获取您的商店的引用,只需使用带有名称的字符串:

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

其他注意事项

  • 您也不需要加载它,.load()因为您已autoLoad在商店配置中设置为 true。
  • Your view should extend Ext.Container, not Ext.dataview.DataView. DataView is used to show data (basically an abstract Ext.List. Because you have a list as an item, you can just put it inside a container.
  • You have set fullscreen: true on the class as well as in the config. You only need to put it inside the config - but it isn't really neccessary because you are creating and inserting your view into Ext.Viewport (in your app.js) which is already fullscreen.
  • You do not need fields config inside your list. You should use a itemTpl to create the template for each row.
于 2012-09-11T22:10:20.630 回答