我正在使用角度j在orderBy
中使用ng-repeat
但是它无法对我的列表进行排序。我的代码是什么?
如何对我的代码进行排序
https://jsfiddle.net/7MhLd/1921/
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.lines = {
"a" : {name:"bb"},
"aa": {name: 'aa'},
"zz": {name:"zz"},
"oo": {name: 'oo'},
"kk": {name:"k"},
"j" : {name: "a"},
"n" : {name:"n"},
"c" : {name: "c"}
}
}
答案 0 :(得分:0)
您必须将对象转换为数组以使其正常工作
<div ng-controller="MyCtrl">
<div ng-repeat="line in lines | orderBy:'name'">
<div class="preview">{{line.name}} {{$index}}</div>
</div>
</div>
和控制器
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.lines = [
{name:"bb"},
{name: 'aa'},
{name:"zz"},
{name: 'oo'},
{name:"k"},
{name: "a"},
{name:"n"},
{name: "c"}
];
}