how to do orderby with angularJS for string array not object array

折月煮酒 提交于 2019-12-22 08:27:02

问题


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>

回答1:


You can use a function in the orderBy-clause like this:

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


来源:https://stackoverflow.com/questions/17064106/how-to-do-orderby-with-angularjs-for-string-array-not-object-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!