我正在使用ag-grid作为应用程序,它只需要数组来显示行。我有一个从API返回的对象。这个调用总是只返回1个对象。我想将对象转换成长度1. 的数组这是我的代码:将对象放入AngularJS中的数组中
jobResult.paged().$promise.then(function (results) {
//ag-grid needs the result to be in an array
var arrayResult = [];
angular.forEach(function(results){
arrayResult.push(results);
});
$scope.jobResult = arrayResult;
if ($scope.lastResultGridOptions.api) {
$scope.lastResultGridOptions.api.setRowData($scope.jobResult);
$scope.lastResultGridOptions.api.sizeColumnsToFit();
}
..rest of function
的results
对象具有从API的数据。但.foreach
函数不会将对象推入数组中。 我错过了什么?
你能告诉我们结果的模式吗? – zero298
[documentation](https://docs.angularjs.org/api/ng/function/angular.forEach)对于如何使用'angular.forEach'非常清楚。也许是时候阅读了? –
你想完成什么? –