作者热门文章
- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我有两个数组,一个用于字母表,第二个用于标签。所以我只想显示该特定字母类别中的相同字母元素示例 -- 苹果必须归入 A 类,而动物园必须归入 Z 类...
fiddle 链接 http://jsfiddle.net/4dGxn/149/
html
<div class="form-group" ng-controller="mainCtrl">
<div ng-repeat="alp in alpha">
<h2>{{alp}}</h2>
<ul>
<li ng-repeat="tag in tags">{{tag}}</li>
</ul>
</div>
</div>
Angular
var app = angular.module("app", []);
app.controller("mainCtrl", ['$scope', function($scope){
$scope.alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p","q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
$scope.tags = ["apple", "dog", "cat", "dad", "baby", "zoo", "love", "hate", "rat", "room", "home", "age", "bad"];
}]);
最佳答案
您可以使用 str.startsWith
来检查元素是否以特定字符开头所以在你的例子中:
<div class="form-group" ng-controller="mainCtrl">
<div ng-repeat="alp in alpha">
<h2>{{alp}}</h2>
<ul>
<li ng-repeat="tag in tags" ng-show="{{tag.startsWith(alp)}}">{{tag}}</li>
</ul>
</div>
</div>
这里是 wirking Fiddle
关于javascript - 如何在 ng-repeat 中显示数组的特定字母表项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36127719/
我是一名优秀的程序员,十分优秀!