2012-04-01 34 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屬性沒有商店實例。