我的数组是:BS
。它的结构是:
Array[317]
0: Object
$$hashKey: "022"
name: "Los Angeles Comm."
.
.
.
..
BS 是一个数组。每个值都是一个带有名称字段的 JSon 对象。
我想根据名称对 BS 的所有值进行排序。我正在尝试:
<option ng-repeat="item in BS | orderBy:item.name" value="{{item.name}}">{{item.name}}</option>
我也尝试过:orderBy:name
和 orderBy:item[name]
。什么都不管用。为什么这不起作用,正确的代码是什么?
最佳答案
看看下面的html
<!DOCTYPE html>
<html ng-app="app">
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
</head>
<body>
<div ng-controller="item">
<ul>
<li ng-repeat="item in items|orderBy:'name'">
{{item.name}}
</li>
</ul>
</div>
<script>
var AppModule = angular.module('app', []);
function item($scope) {
$scope.items = [{ name: 'tur' }, { name: 'abc' }, { name: 'xyx' }];
}
</script>
</body>
</html>
关于javascript - orderBy 没有按预期工作 : Angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16455832/