2011-09-23 34 views
0

我有一個TabPanel,裏面有一個Tabbar和四個面板。當面板變得可見時,我想通過AJAX調用爲第四個面板加載HTML內容。當在面板顯示時在Sencha觸摸中加載帶AJAX的html數據

AJAX函數從服務器獲取數據並將其放置在面板中,該面板使用面板更新功能。問題是當面板變得可見時如何調用這個函數。一個簡化的版本是:

Pages.Contact = new Ext.Panel({ 

    title: 'Contact', 
    html: 'test data', 
    iconCls: 'user', 
    cls: 'cHome', 

    activate: function() { 
     Pages.Contact.update("my ajax data"); 
    } 

}); 

當我去我的面板主體內容不受影響。有人知道這裏出了什麼問題嗎?我已經嘗試用render和show替換activate。

回答

0

的解決方案是使用:

beforecardswitch:function(object, newCard, oldCard, index, anim) { 

如由Ilya139由與該對象參數作爲第一參數。

然後索引變量返回正確的卡號。

1

添加事件的監聽器,你需要做的

listeners: { 
       activate: function(){ 
       console.log('activate fired'); 
       } 
    }, 

但是,這不是你想要聽的事件。這是更好地監聽TapPanel對象上beforecardswitch,例如:

listeners: { 
       beforecardswitch:function(newCard, oldCard, index, anim){ 
        if(index == 3){ 
        //loadJson and update card. 
         // you may want to use this also 
         newCard.setLoading(true); 
         //and after the json request has finished set it to false. 
        }    
       } 
    }, 
+0

感謝您的回覆! 如果我使用: 聽衆:{ beforecardswitch:功能(NEWCARD,老卡,索引,動畫){ 的console.log(索引); } }, 索引不是數字而是一個對象。有任何想法嗎? –

+0

用console.log(index);把它輸出到控制檯,看看你的卡是什麼。然後把它放在if語句中。 – ilija139

+0

我做了,它變成了整個選項卡對象,它看起來與newcard對象相同。 –