2011-08-21 84 views
0

有菜單按鈕(「客戶端」),帶客戶端列表(按名稱排序)的樹面板和具有選定客戶端詳細信息的查看器。還有選擇更改動作..如何等待將數據加載到商店中

我的任務 - 按鈕單擊切換到客戶端視圖,並選擇並加載第一個客戶端的細節,每次點擊按鈕。我的問題 - 商店沒有加載,等到ext js會自動將數據加載到商店?

我控制器代碼:

me.control({ 
     '#nav-client': { 
      click: me.onNavClientClick 
     }, 
    ... 
     'clientlist': { 
     // load: me.selectClient, 
      selectionchange: me.showClient 
     } 
    }); 

    onNavClientClick: function(view, records) { 
     var me = this, 
      content = Ext.getCmp("app-content"); 
     content.removeAll(); 
     content.insert(0, [{xtype: 'clientcomplex'}]); 
     var first = me.getClientsStore().first(); 

     if (first) { 
      Ext.getCmp("clientList").getSelectionModel().select(me.getClientsListStore().getNodeById(first.get('clientId'))); 
     } 
    }, 
... 

兩個主要問題:

  • 是它在我的情況很好的解決方案? (選擇在樹面板第一客戶端)

    var first = me.getClientsStore().first(); 
    // i use another store to get first record because of i dont know how to get first record (on root level) in TreeStore 
    ... 
    Ext.getCmp("clientList").getSelectionModel().select(me.getClientsListStore().getNodeById(first.get('clientId'))); 
    

我知道這個代碼工作正常的情況下 「載:me.selectClient,」(但僅限一次),

  • 如果我把這段代碼上按一下按鈕 - 我看到錯誤

    Uncaught TypeError: Cannot read property 'id' of undefined 
    

因爲me.getC的lientsListStore()沒有加載..所以如何檢查這家商店的加載狀態,並等待一些,直到這家商店將完全自動加載?..

謝謝!

回答

0

您可以收聽商店「加載」事件。像這樣:

... 
onNavClientClick: function(view, records) { 
    var me = this; 

    // if the store isn't loaded, call load method and defer the 'client view' creation 
    if (me.getClientsStore.getCount() <= 0) { 
    me.getClientsStore.on('load', me.onClientsStoreLoad, me, { single : true}); 
    me.getClientsStore.load(); 
    } 
    else { 
    me.onClientsStoreLoad(); 
    } 
}, 

onClientsStoreLoad : function() { 
    var me = this, 
     content = Ext.getCmp("app-content"); 
    content.removeAll(); 
    content.insert(0, [{xtype: 'clientcomplex'}]); 
    var first = me.getClientsStore().first(); 

    if (first) { 
     Ext.getCmp("clientList").getSelectionModel().select(me.getClientsListStore().getNodeById(first.get('clientId'))); 
    } 
}, 
... 
相關問題