gpt4 book ai didi

javascript - orderBy 没有按预期工作 : Angularjs

转载 作者:IT王子 更新时间:2023-10-29 03:19:49 26 4
gpt4 key购买 nike

我的数组是: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:nameorderBy: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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com