angularjs – 如何使用角度orderBy过滤器按字母顺序对字符串数组进行排序?

前端之家收集整理的这篇文章主要介绍了angularjs – 如何使用角度orderBy过滤器按字母顺序对字符串数组进行排序?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个包含国家列表的模型
$scope.model = {
    name: "foo",countriesVisited: ["CA","AR","GB","FR","MX","AU","IE","RU","IT","ES","IN","US","NL","DE","CL","BR","JP","NZ","PL"]
  }

使用ng-repeat指令按照显示的顺序列出它们.
设置orderBy过滤器会对商品进行排序,但订单看似随机.见这plunker

取下过滤器并观察输出偏移.将其粘贴回来,这是一个奇怪的顺序.

有没有办法让countriesVisited数组在不将其移动到自己的$scope变量的情况下进行排序?

<li ng-repeat="country in model.countriesVisited | orderBy:'toString()'">

猜你在找的Angularjs相关文章