AngularJS 重复过滤以字母 G 结尾的字符串

AngularJS repeat filter strings ending with the letter 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">, &nbsp;</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">,&nbsp; </span></span>
  </span>
</div>

我的东西不起作用。有人可以帮我吗?

我不确定您从哪里得到 ng-filter 属性。但是,这不是 AngularJS.

ng-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');
    };