2013-03-07 12 views
2

我有:在賣場中創建煎茶 - store.each() - 數據無法獲得,他們只是深藏於數據類

Ext.define("catcher.view.Login", { 
    extend: "Ext.form.Panel", 
// creating login form, including selectfield 

商店「錦標賽」(自動加載:真),有其模型。 Everyting被設置。 需要動態地(在view.Login類仍然)填寫selectfield:

initialize: function(){ 
     var store = Ext.getStore("Tournaments");   
     var options = new Array(); 
     store.each(function(radek){ 
      options[radek.get("tournament_id")] = radek.get("tournament_name"); 
     }); 
    } 

我不想使用store:"Tournaments"配置選項,因爲以後form.submit的,();不會從selectfield發送正確的數據。

有問題:console.log(store.getCount());返回0使用store.add({ ... })我可以添加任何東西,getCount將()返回corrent數(0 +添加())。

奇怪的部分:console.log(store)返回整個類,包括data對象與所有項目裏面。下一個奇怪的部分 - 如果我在控制器中使用相同的代碼,一切正常,Store正確加載,我可以使用mystore.each();

回答

5

存儲加載是異步的,當您訪問它時,它不會被加載。您需要聆聽商店加載事件。

喜歡的東西:

store.on('load', function(storeRef, records, successful){ 
    //Loop through records 
}, this); 

on() documentation

load event documentation

+0

謝謝,太好了。我認爲當數據加載到'data'類時,它們也準備好使用。 – 2013-03-08 11:38:20