angularjs - AngularJS 重复过滤字符串以字母 G 结尾
问题描述
我有一个 AngularJS 应用程序,需要在一行上显示以 G 结尾的对象属性,在另一行上显示没有 G 的对象属性:
<div class="col"><strong>Grass</strong>
<span ng-repeat="(key, value) in player.ranking" ng-
filter="value.endsWith('G') = true">
<span class="text-success">{{key.replace('Pool', '')}} {{value}}<span ng-
if="!$last">, </span></span></span>
</div>
<div class="col"><strong>Beach:</strong>
<span ng-repeat="(key, value) in player.ranking" ng-
filter="!value.endsWith('G')">
<span class="text-warning">{{key.replace('Pool', '')}} {{value}}<span ng-
if="!$last">, </span></span>
</span>
</div>
我所拥有的不起作用。有人可以帮帮我吗?
解决方案
我不确定你ng-filter
从哪里得到这个属性。但是,这不是AngularJSng-repeat
中的有效过滤器。
正确的格式是:
item in items | filter:searchText
在您的 HTML 中,它看起来像:
<ul ng-repeat="item in items | filter:query ">
<li>{{item.name}}</li>
</ul>
因此,解决问题的最快方法是使用过滤器功能
html
<ul ng-repeat="item in items |
filter: filterFunction ">
<li>{{friend.name}} ({{friend.age}})</li>
</ul>
JS
$scope.filterFunction = function(value) {
return value.endsWith('G');
};
推荐阅读
- react-native - iOS 应用程序如何与以太坊钱包交互
- android - 调用 FirebaseInstanceId.getToken 的行为
- javascript - MVC 导航栏主页按钮获取请求的问题
- amazon-web-services - 保护 S3 资产免遭直接下载
- python - Errno 2 没有这样的文件或目录:'/storage/test.txt'
- docker - Does Docker image supporting Nvidia gpu on a cpu machine
- google-apps-script - script to split a string google sheet
- ios - ionic2-calendar/calendar time difference
- rdf - 如何提取/获取本体中的所有术语(类/属性)
- assembly - 如何在文本模式程序集中换行