如何用angularJS为字符串数组而不是对象数组做orderby

时间:2013-06-12 11:17:55

标签: angularjs sql-order-by

我在angularJS中有一个字符串数组,我想为它的元素做一些排序我尝试这个代码但它不起作用我不知道为什么任何人有任何想法

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

1 个答案:

答案 0 :(得分:7)

您可以在orderBy子句中使用如下函数:

<li data-ng-repeat="country in countries | filter:name | orderBy:'toString()'"> {{ country }}</li>