2012-04-01 68 views
1

这里是我的应用程序代码:煎茶触摸2 - 我Ext.List犯规出现

Ext.application({ 
    name: 'ProjectName', 
    appFolder: APP_URL + "app", 

    // phoneStartupScreen: 'LOGO.png', 

    controllers: ['Site_inside'], 
    views: ['Inside_spotlist'], 
    models: ['Spot'], 
    stores: ['Spots'], 

    launch: function() { 
     //bootstrap 
     console.log("inner site bootstrap"); 

     //var spotlist = Ext.create("ProjectName.view.Inside_spotlist"); 

     Ext.Viewport.add({ 
      xclass: 'ProjectName.view.Inside_spotlist' 
     }); 

     return true; 
    } 
}); 

查看 'Inside_spotlist' 代码:

Ext.define('ProjectName.view.Inside_spotlist', { 
    extend: 'Ext.List', 
    alias: 'spotlist', 
    xtype: 'spotlist', 

    requires: [ 
     'ProjectName.store.Spots' 
    ], 

    config: { 
     store: 'Spots', 
     itemTpl: '{first_name} {last_name}' 
    }, 

    initialize: function() { 
     console.log("spolist loaded"); 
    } 
}); 

'现货' 模式的代码:

Ext.define("ProjectName.model.Spot", { 
    extend: 'Ext.data.Model', 

    config: { 
     fields: [ 
      { 
       name: 'firstName', 
       type: 'string' 
      }, 
      { 
       name: 'lastName', 
       type:'string' 
      } 
     ] 
    } 
}); 

最后,斑点店:

Ext.define("ProjectName.store.Spots", { 
    extend: 'Ext.data.Store', 

    config: { 
     listeners: { 
      load: function() { 
       console.log("loaded store"); 
      } 
     }, 

     autoLoad: true, 
     autoSync: true, 

     model: 'ProjectName.model.Spot', 
     data:[ 
      { 
       firstName: 'test', 
       lastName: 'test2' 
      } 
     ] 
    } 
}); 

它加载正常(出现控制台消息,没有错误或警告消息),但没有出现带有我的测试数据的列表。如果我试图“上下”抓取站点,右侧的iOS风格的滚动条会显示,但列表中没有数据。

这段代码有什么问题?

回答

0

你可以试试这个:

Ext.Viewport.add(
    Ext.create('ProjectName.view.Inside_spotlist') 
); 

,而不是这样的:

Ext.Viewport.add({ 
    xclass: 'ProjectName.view.Inside_spotlist' 
}); 

另外....

你可以试试这个:

config: { 
    store: 'ProjectName.store.Spots', 
    itemTpl: '{first_name} {last_name}' 
} 

代替这个:

config: { 
    store: 'Spots', 
    itemTpl: '{first_name} {last_name}' 
} 
0

我建议你按照惯例在这里描述:Loading data into List using store sencha touch 2

虽然在这个问题的答案的评论似乎表明,谁问这个问题的人在做它自己的方式,我不知道这是如何工作的。尝试按照答案中描述的方式进行操作,即使用Ext.create创建商店实例,然后使用Ext.data.StoreManager.lookup在任何需要的地方查找和使用该实例。这里的问题是,列表中的store属性没有商店实例。