首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何让orderby过滤器对字符串数组起作用?

如何让orderby过滤器对字符串数组起作用?
EN

Stack Overflow用户
提问于 2013-01-24 10:49:40
回答 2查看 55.6K关注 0票数 87

下面是不起作用的代码: 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'];  
});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-07 12:04:30

您可以按方法排序,因此可以使用toString方法

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

Stack Overflow用户

发布于 2013-01-24 12:02:50

编写一个custom filter

app.filter('mySort', function() {
    return function(input) {
      return input.sort();
    }
  });

HTML:

<ul ng-repeat="strVal in arrVal|filter:searchText|mySort">

Fiddle

票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14493116

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档