读书人

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

发布时间: 2013-03-27 11:22:42 作者: rapoo

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


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

读书人网 >JavaScript

热点推荐