找回密码
 注册
搜索
热搜: java php web
查看: 773|回复: 1

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

[复制链接]
发表于 2009-1-25 19:04:31 | 显示全部楼层 |阅读模式
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,简捷又方便
发表于 2009-1-25 20:58:04 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|软晨网(RuanChen.com)

GMT+8, 2024-9-20 13:53

Powered by Discuz! X3.5

Copyright © 2001-2023 Tencent Cloud.

快速回复 返回顶部 返回列表