Ext2.0.2升級到2.1了,開發也要與時俱進嘛。雖說這直接替換了2.0.2,但是卻遇到一個不大不小的麻煩。ExtJs Panel的遠程頁面載入是一個非常好的功能,之前的有些調用代碼在2.1卻無法顯示最新的資料了。
API DOC 如是說:
Ext.Panel.autoLoad
A valid url spec according to the Updater Ext.Updater.update method. If autoLoad is not null, the panel will attempt to load its contents immediately upon render.
The URL will become the default URL for this panel's body element, so it may be refreshed at any time.
雖然說是"refreshed at any time",但是在2.1,這次IE下卻不refresh了。大家都知道,IE下AJAX載入資料有一個問題,就是同一地址第二次取時取的是快取資料。2.1沒有重新整理緩衝了,肯定和這個有關,於是自己在請求URL尾部加了一個時間串參數,頁面就能夠重新整理了。
光解決問題還不夠,看看源碼究變了些什麼地方吧:
既然所是Ext.Updater.update method,那麼在ext-all-debug找到此代碼,2.0.2裡面多了一個prepareUrl調用,如下:
method = method || (params ? "POST" : "GET");
if(method == "GET"){
url = this.prepareUrl(url);
}
prepareUrl的代碼如下:
prepareUrl : function(url){
if(this.disableCaching){
var append = "_dc=" + (new Date().getTime());
if(url.indexOf("?") !== -1){
url += "&" + append;
}else{
url += "?" + append;
}
}
return url;
},
看來和我想得沒錯,也是利用了時間串來區分每次請求。但是Ext2.1卻沒有此段調用,跟蹤代碼才發現直接利用Exe.Ajax.disableCaching來判斷了,由autoLoad傳入對象的nocache來控制的,之前偷懶唯寫了url和scripts屬性,Ext2.0的版本直接判斷GET就在Ext.Updater.update裡處理了,於是可以不寫nocache,而2.1卻統一由Exe.Ajax.request來處理,因此,就必須寫nocache: true了。
即:
{
xtype: 'panel',
id: node.attributes.idIndex,
title: node.text,
iconCls: 'tabs',
closable:true,
autoLoad: {url: disabledCacheUrl, nocache: true, scripts:true}
}
所以,最後還是直添上nocache:true,簡捷又方便。