Ext2.0升级至Ext2.1 Ext.Panel的AJAX加载方式autoLoad参数使用的变化

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值