如何做排序依据与angularJS为字符串数组没有对象数组 [英] how to do orderby with angularJS for string array not object array
本文介绍了如何做排序依据与angularJS为字符串数组没有对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个angularJS字符串数组和我想要做的某种形式的为它的元素我试试这个code,但它不工作,我不知道为什么任何人有任何想法。
i have an string array in angularJS and i want to do some kind of sort for it's element i try this code but it isn't work and i don't know why any one has any idea
<div id="cpntainer" data-ng-init="countries = ['Syria','Lebanon','Jordon','Egypt']">
Country Name <br />
<input type="text" data-ng-model="name" /> <br />
<ul>
<li data-ng-repeat="country in countries | filter:name | orderBy:country:false "> {{ country }} </li>
</ul>
</div>
推荐答案
您可以在排序依据子句像这样使用函数
You can use a function in the orderBy-clause like this:
<li data-ng-repeat="country in countries | filter:name | orderBy:'toString()'"> {{ country }}</li>
这篇关于如何做排序依据与angularJS为字符串数组没有对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文