Javascript 条件排序-AngularJs
我一直试图做的是有条件地设置值,通过这些值来排序我的ng repeat值 我尝试使用条件方法添加ng类,如下所示:Javascript 条件排序-AngularJs,javascript,angularjs,Javascript,Angularjs,我一直试图做的是有条件地设置值,通过这些值来排序我的ng repeat值 我尝试使用条件方法添加ng类,如下所示: ng-class="{'active':item.selected}" 并将其与date orderBy方法相结合: ng-repeat="item in filterPosts | orderBy:['yyyy','mm','dd']" 这将导致以下两种情况之一,但不幸的是,所有这些都不起作用 ng-repeat="item in items | orderBy: [{('
ng-class="{'active':item.selected}"
并将其与date orderBy方法相结合:
ng-repeat="item in filterPosts | orderBy:['yyyy','mm','dd']"
这将导致以下两种情况之一,但不幸的是,所有这些都不起作用
ng-repeat="item in items | orderBy: [{('yyyy','mm','dd'):(sortBy=='Recently Added')}]"
ng-repeat="item in items | orderBy: [{'yyyy':(sortBy=='Recently Added')}]"
ng-repeat="item in items | orderBy: [{'yyyy':sortBy=='Recently Added'}]"
如上所示,最近添加的字符串将从下拉列表中选择,以选择过滤器选项
如果SortBy=true
ng-repeat="item in items | orderBy: [{'yyyy':sortBy}]"
关于如何使这项工作,或者如果这是可能的,有什么想法吗
更新
这是一个
正如你将看到的,它不起作用
如果取消对此行的注释:
<!--li ng-repeat="item in activities"> -->
并注释掉这一行:
<li class="item_wrap" ng-repeat="item in activities | orderBy: [{'yyyy':recent}]">
您将看到列表项首先,您的select必须具有ng change指令才能通过参数分配排序。如下
<select ng-init="sortBy='+date'" ng-model="sortType" ng-change="sortBy= sortType=='Recently Added' ? '-date':sortType=='Name' ? '+name':'+date';">
<option>Recently Added</option>
<option>Name</option>
</select>
它只是一个字符串值。将从下拉列表中选择筛选选项您可以创建一个Plunk吗?我将添加一个简短的选项您的项目是否具有“yyyy”属性?已添加了一个示例Hanks。我现在就试试这其实是一个简单的方法。谢谢你的帮助
ng-repeat="item in items | orderBy:sortBy:true"