Javascript AngularJS多维数组按顺序排列
我有一个多维数组,正在解析为JSON,我想在AngularJS中使用“order by”。我得到了这个错误:error:[orderBy:notarray]预期的数组,但收到的是:13Javascript AngularJS多维数组按顺序排列,javascript,php,angularjs,json,multidimensional-array,Javascript,Php,Angularjs,Json,Multidimensional Array,我有一个多维数组,正在解析为JSON,我想在AngularJS中使用“order by”。我得到了这个错误:error:[orderBy:notarray]预期的数组,但收到的是:13 <div ng-repeat="x in thread track by x.Id | orderBy: x.Id"> } } 如果有人能帮忙,我将不胜感激 非常感谢,使用orderBy时有一些限制和规则迭代对象对象(用作关联数组或哈希)此标题是您试图实现的。使用orderBy时有一些限制和规则迭代
<div ng-repeat="x in thread track by x.Id | orderBy: x.Id">
}
}
如果有人能帮忙,我将不胜感激
非常感谢,使用orderBy时有一些限制和规则<代码>迭代对象对象(用作关联数组或哈希)此标题是您试图实现的。使用orderBy时有一些限制和规则<代码>迭代对象对象(作为关联数组或散列)此标题是您试图实现的。替换:
<div ng-repeat="x in thread track by x.Id | orderBy: x.Id">
与:
更换:
<div ng-repeat="x in thread track by x.Id | orderBy: x.Id">
与:
我不会在$scope中对数组进行排序(即使在我看来,您不需要动态排序),我宁愿在控制器中使用内置Javascript的排序方法对其进行排序(更快) 例如,在返回JSON之后
angular.module('sample-app',[])
.controller('SampleController',['$http','$scope',函数($http,$scope){
$scope.test='Array Sort';
$http.get('https://jsonplaceholder.typicode.com/posts/')
.然后(函数(结果){
//订单id描述(更改ASC的a和b位置)
result.data.sort(函数(a,b){
返回b.id-a.id
});
//注入范围
$scope.items=result.data;
});
}]);代码>
{{test}}
-
{{item.id}
我不会在$scope中对数组进行排序(即使在我看来,您不需要动态排序),我宁愿在控制器中使用内置Javascript的排序方法对其进行排序(更快)
例如,在返回JSON之后
angular.module('sample-app',[])
.controller('SampleController',['$http','$scope',函数($http,$scope){
$scope.test='Array Sort';
$http.get('https://jsonplaceholder.typicode.com/posts/')
.然后(函数(结果){
//订单id描述(更改ASC的a和b位置)
result.data.sort(函数(a,b){
返回b.id-a.id
});
//注入范围
$scope.items=result.data;
});
}]);代码>
{{test}}
-
{{item.id}
<div ng-repeat="x in thread | orderBy: 'Id' track by x.Id">