如何使 orderby 过滤器对字符串数组起作用? [英] How to make orderby filter work on array of strings?

查看:25
本文介绍了如何使 orderby 过滤器对字符串数组起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是不起作用的代码:演示:http://jsfiddle.net/8dt94/63/

<input type="text" ng-model="searchText"/><ul ng-repeat="strVal in arrVal|orderBy|filter:searchText" ><li>{{strVal}}</li>

var app=angular.module('myApp', []);app.controller('MyCtrl', function ($scope,$filter) {$scope.arrVal = ['一','二','三','四','五','六'];});

解决方案

可以按方法排序,所以可以使用toString方法

Here is the code which is not working: Demo: http://jsfiddle.net/8dt94/63/

<div ng-controller="MyCtrl">    
    <input type="text" ng-model="searchText" />
  <ul ng-repeat="strVal in arrVal|orderBy|filter:searchText" >
      <li>{{strVal}}</li>
  </ul>
</div>

var app=angular.module('myApp', []);
app.controller('MyCtrl', function ($scope,$filter) {
  $scope.arrVal = ['one','two','three','four','five','six'];  
});

解决方案

You can order by a method, so you can use the toString method

<ul ng-repeat="strVal in arrVal | orderBy:'toString()' | filter:searchText">

这篇关于如何使 orderby 过滤器对字符串数组起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆