一个页面由多个组件组成,每个组件都重后台取数据,使用Ext.Ajax.request()方式
Ext.Ajax.request(
{
url : 'rightAction!methodXX1.action',
}
)Ext.Ajax.request(
{
url : 'rightAction!methodXX2.action',
}
)Ext.Ajax.request(
{
url : 'rightAction!methodXX3.action',
}
)
Wsd.web.chart = function() {
var w = 100;
var h = 230;
var obj = document.getElementById('web-area-container');
w = obj.offsetWidth;
w = w / 3;
// 区域
this.showChart(w, h, 'wtoEMsColAction!GZtoGD.action', 'GZtoGD',
'MSColumn3D.swf');
this.showChart(w, h, 'wtoEMsColAction!YNtoGD.action', 'YNtoGD',
'MSColumn3D.swf');
this.showChart(w, h, 'wtoEMsColAction!GXtoGD.action', 'GXtoGD',
'MSColumn3D.swf');// 地域 var obj = document.getElementById('web-factory-container'); w = obj.offsetWidth; w = w / 3; this.showChart(w, h, 'wtoEMsColAction!tianYi.action', 'tianYi', 'MSColumn3D.swf'); this.showChart(w, h, 'wtoEMsColAction!tianEr.action', 'tianEr', 'MSColumn3D.swf'); this.showChart(w, h, 'wtoEMsColAction!longTan.action', 'longTan', 'MSColumn3D.swf');
}
Wsd.web.chart.prototype = {
showChart : function(w, h, url, chartId, swf) {
var xmlStr = Wsd.golob.Synchronize(url);
var chart = new FusionCharts('../scripts/fusionCharts/swf/' + swf,
chartId + '_flash', w, h, '0', '0');
chart.setDataXML(xmlStr);
chart.setTransparent(true);
chart.render(chartId);
}}
//自己定义一个同步的方法。作为全局的方法使用
Wsd.golob.Synchronize = function(url) {
function createXhrObject() {
var http;
var activeX = ['MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP',
'Microsoft.XMLHTTP'];
try {
http = new XMLHttpRequest();
} catch (e) {
for (var i = 0; i < activeX.length; ++i) {
try {
http = new ActiveXObject(activeX[i]);
break;
} catch (e) {
}
}
} finally {
return http;
}
};var conn = createXhrObject(); conn.open("GET", url, false); conn.send(null); if (conn.responseText != '') { var returnVal=conn.responseText; if (returnVal.indexOf("Session Expired") != -1) {//判断session超时 new Wsd.golob.Redirect(); } else { return returnVal; } } else { return null; }
};
LZ的这种情况也是在页面初始的时候吧,在页面初始的时候改成同步是不会有影响的,Ext所有的组件请求都是异步的,LZ可以把1的数据通过同步的方式请求,然后通过设值的方式提供给2,
[code="javascript"]
var data_;//全局变量
//自己封装的ajax请求LZ只要看获得数据的方式
ajaxRequest(url,参数, function callback(options, success, response) {
var rs = Ext.decode(response.responseText);
if (!rs.actionErrors) {
data_= rs.datas;//获得数据
} else {
showErrorMessageBox(rs.actionErrors);
}
},false//同步请求的参数
);
组件1.setValue(data_);
组件2.setValue(data_);
[/code]
一般不会出现这种情况,最好贴一下代码
以前做树加载也碰过这情况(当时是3棵树同时展开),后来用同步(初始只展开一个)。