首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

函数返回一组对象,为何只等到一个!

2013-03-27 
【求助】函数返回一组对象,为何只等到一个!。。function GetConditons(){Ext.Ajax.request({url : servers/vi

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


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;
}

热点排行