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]请教怎么才能等到全部啊?

解决方案 »

  1.   

    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;}
    这里return是没有用的 如果你需要另外的函数来处理的话
    return condi改成 functionname(condi)
      

  2.   

    没用过EXTJS,不过感觉上。去掉eval()试试?JSON的格式是什么?
      

  3.   

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

  4.   

    首先,ajax是异步请求,你那样搞肯定是得不到你想要的结果的其次,var condi = new GetConditons();这玩意返回的是一个GetConditons的实例,肯定是一个object没跑了再次,var condi = eval(json.CONDITIONS);跟var condi = new GetConditons();完全不是一回事
    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);//这样应该可以了
      

  5.   

    下面这样吧
    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 ;
    }
      

  6.   


    --------
    这样返回是对了返回的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}];
    页面上可以显示这些控件
      

  7.   

    没有用过ExtJS,但只要condi的数据格式和上面的一样,应该是没有问题的。你用alert(JSON.stringify(condi));看下数据格式对不对。
      

  8.   


    -----
    [[{"XTYPE":"'xCengJi'"},{"XTYPE":"'xCityOrCountry'"},{"XTYPE":"'xFenLei4'"},{"XTYPE":"'xStDate'"},{"XTYPE":"'xEdDate'"}]]外面多了个[],如果我人工处理掉,objs.push(condi);又会报错!
      

  9.   

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

  10.   


    ---谢谢!已经解决了!
    我后台的数据是包含了[]
    我自己处理了下就可以了:
    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);
    }