2017-02-10 41 views
0

我正在嘗試使用某些DDL過濾器(從獲取數據)創建ui網格。如果我嘗試使用async:false,所有工作都完美無缺。這是電話:使用異步調用創建ui網格

var Documents = []; 

var solutionSetColumn = {}; 
var solutionSetFilters = []; 

LoadData = function() { 
     Documents = []; 
     $.ajax({ 
      type: "POST", url: url, 
       success: function (data) { 
       Documents = data.d; 
      }, 
      error: function (err) { 
      } 
     }); 
    } 
} 

$.ajax({ 
    type: "POST", url: url, 
    success: function (data) { 
     solutionSetColumn = { field: 'SolutionSet', displayName: 'Solution Set', width: 190, filter: { type: uiGridConstants.filter.SELECT, selectOptions: data.d } }; 
    }, 
    error: function (err) { 
     solutionSetColumn = { field: 'SolutionSet', displayName: 'Solution Set', width: 190 } 
    } 
});  

LoadData(); 

gridOptions = { 
    enableHorizontalScrollbar: 2, 
    enableVerticalScrollbar: 0, 
    enableFiltering: true, 
    data: Documents, 
    columnDefs: [ 
     { field: 'Name', displayName: 'Nome File', width: 200 }, 
     solutionSetColumn 
    ] 
} 

$scope.gridOptions = gridOptions; 
}); 

如何獲得所有async沒有gridOption錯誤像colDef undefined?顯然沒有setTimeout!謝謝

回答

0

您需要將您的$ scope.gridOptions(和選項定義)移動到您的ajax調用的成功路徑中。

+0

'TypeError:無法讀取undefined'的屬性'data',顯然,call始終是異步的... –

+0

問題是,您有多個asyn調用。你可以把每一個放入其父(如我所建議的),或使用承諾。請參閱http://stackoverflow.com/questions/15299850/angularjs-wait-for-multiple-resource-queries-to-complete – Gerfried