Ext2.0升級至Ext2.1 Ext.Panel的AJAX載入方式autoLoad參數使用的變化

來源:互聯網
上載者:User

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,簡捷又方便。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.