在AngularJs自定义排序 [英] Custom Sorting in AngularJs

查看:176
本文介绍了在AngularJs自定义排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像

    {"facebook":"aravind@facebook.com",
            "homeAddress":"26, New Street, Blr",
            "officeAddress":"31, Old Office Street, Blr",
            "city":"Blr",
name:"aravind"
    },
    {"facebook":"ashok@facebook.com",
            "homeAddress":"26, New Street, che",
            "officeAddress":"31, Old Office Street, che",
            "city":"che",
name:"ashok"
    }

在角JS,我已经按名称排序字段defaultly,我有一个文本框和按钮

In Angular js, I have ordered the field by name defaultly, I have one text box and button

<input type="text" class="form-control" ng-model="search.location" />
          <div class="search" ng-click="locationSorting()"></div>

当我按一下按钮输入文本框的位置后,(对Ex:BLR)。该名单由地点排序。

When i click the button after enter the location in text box( For Ex: blr). The list is sorted by location.

目前我已经完成按位置过滤器。但我不想过滤。我想排序列表

Currently i have finishing the filter by location. But i dont want filtering. I want sorting the list

 var locationFilterHome = {homeAddress: location};
        filterData = $filter('filter')(data, locationFilterOffice)

我使用上述code过滤。如何根据位置做分类

I am using above code for filtering. How to do sorting based on location

推荐答案

从我明白了什么,你要问如何通过在控制器的位置对数据进行排序。
一种方法是使用排序依据过滤器。你可以使用它,就像你使用过滤器过滤器:筛选数据= $过滤器('排序依据')(数据,'位置');

From what I understand, you wish to ask how to sort the data by location in the controller. One way would be to use the 'orderBy' filter. You can use it just like you use the 'filter' filter: filterData=$filter('orderBy')(data,'location');

请为我所想说的一个例子看看这个普拉克:?//plnkr.co/edit/BU4DaxlBSNcmRkXG6krc p = preVIEW

Please check out this plunk for an example of what I am trying to say: http://plnkr.co/edit/BU4DaxlBSNcmRkXG6krc?p=preview

angular.module('app',[])
  .controller('mainCtrl',function($filter){
var data=[{"facebook":"aravind@facebook.com",
                "homeAddress":"26, New Street, Blr",
                "officeAddress":"31, Old Office Street, Blr",
                "city":"Zlr",
    name:"aravind"
        },
        {"facebook":"ashok@facebook.com",
                "homeAddress":"26, New Street, che",
                "officeAddress":"31, Old Office Street, che",
                "city":"che",
    name:"ashok"
        }];

    var modifiedData=$filter('orderBy')(data,'city');
    console.log(modifiedData);
  })

这篇关于在AngularJs自定义排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆