如何使字符串数组排序依据过滤器的工作? [英] How to make orderby filter work on array of strings?

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

问题描述

下面是code这是不工作:演示: http://jsfiddle.net/8dt94/63/

 < D​​IV NG控制器=MyCtrl>
    <输入类型=文本NG模型=SEARCHTEXT/>
  < UL NG重复=strVal在arrVal |排序依据|过滤器:SEARCHTEXT>
      <立GT; {{strVal}}< /李>
  < / UL>
< / DIV>VAR应用= angular.module('对myApp',[]);
app.controller('MyCtrl',函数($范围,$过滤器){
  $ scope.arrVal = ['一','二','三','四','五','六'];
});


您可以通过以下方法排序,所以你可以使用toString方法

 < UL NG重复=strVal在arrVal |排序依据:'的toString()|过滤器:SEARCHTEXT>

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">

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

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