日期:2014-05-16  浏览次数:20313 次

【求助】函数返回一组对象,为何只等到一个!。。


function GetConditons(){
  Ext.Ajax.request({
url : 'servers/viewdata/Conditions.ashx?_menuID='+uid,
method:'POST',
timeout:10000,
async : false,
success:function(response,option){
if(response.responseText=="数据为空"){   
              Ext.MessageBox.hide();
              Ext.MessageBox.alert('提示','数据为空')};
var json = Ext.JSON.decode(response.responseText);
var condi = eval(json.CONDITIONS);
alert(condi);//[object Object],[object Object],[object Object],[object Object],[object Object]
return condi;
}
});

var condi = new GetConditons();
alert(condi);//[object Object]

---------
函数里面alert结果:[object Object],[object Object],[object Object],[object Object],[object Object];
函数外却只有一个对象:[object Object]

请教怎么才能等到全部啊?

------解决方案--------------------
success 里面的return对GetConditons函数没有意义。

function GetConditons() {
var objs = [];
Ext.Ajax.request({
url : 'servers/viewdata/Conditions.ashx?_menuID=' + uid,
method : 'POST',
timeout : 10000,
async : false,
success : function (response, option) {
if (response.responseText == "数据为空") {
Ext.MessageBox.hide();
Ext.MessageBox.alert('提示', '数据为空')
};
var json = Ext.JSON.decode(response.responseText);
var condi = eval(json.CONDITIONS);
objs.push(condi);
}
});
return objs;
}