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]请教怎么才能等到全部啊?
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]请教怎么才能等到全部啊?
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;}
这里return是没有用的 如果你需要另外的函数来处理的话
return condi改成 functionname(condi)
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;
}
function GetConditons(){
Ext.Ajax.request({
url : 'servers/viewdata/Conditions.ashx?_menuID='+uid,
method:'POST',
timeout:10000,
async : ture,//这里改成同步
success:function(response,option){
if(response.responseText=="数据为空"){
Ext.MessageBox.hide();
Ext.MessageBox.alert('提示','数据为空');
}else{
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);//这样应该可以了
function GetConditons() {
var result;
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);
result = condi;
}
});
return result ;
}
--------
这样返回是对了返回的object我在一个pannel里面这样调用
listeners :{
"render":function(obj){this.add(condi)}
}
有什么问题?页面上没有加载这个condi里的控件。如果我直接写成
condi=[{xtype :'xCengJi',hidden:false},{xtype :'xCityOrCountry',hidden:false},{xtype :'xFenLei4',hidden:false},{xtype :'xStDate',hidden:false},{xtype :'xEdDate',hidden:false}];
页面上可以显示这些控件
-----
[[{"XTYPE":"'xCengJi'"},{"XTYPE":"'xCityOrCountry'"},{"XTYPE":"'xFenLei4'"},{"XTYPE":"'xStDate'"},{"XTYPE":"'xEdDate'"}]]外面多了个[],如果我人工处理掉,objs.push(condi);又会报错!
var result = [];
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);
result = condi;
}
});
return result ;
}
---谢谢!已经解决了!
我后台的数据是包含了[]
我自己处理了下就可以了:
var res = eval(json.CONDITIONS);
var condi = '';
for (var i=0;i<res.length;i++){
condi = '{xtype :' + res[i].XTYPE + ',hidden:false}';
alert(condi);
condi = eval('('+condi+')');
objs.push(condi);
}