admin管理员组

文章数量:1425676

I have a couple of input fields, we can use an input field with the name of search as an example. when someone types into that field i want to be able to filter the results of an object. but i want to do the filter server side not client side. i have a database with a lot of records so i don't want to have to return them all and do the filtering client side, it really slows things down. id also like to implement pagination with angular js. any pointers? or a direction i should head?

I use mongodb as a db store

I have a couple of input fields, we can use an input field with the name of search as an example. when someone types into that field i want to be able to filter the results of an object. but i want to do the filter server side not client side. i have a database with a lot of records so i don't want to have to return them all and do the filtering client side, it really slows things down. id also like to implement pagination with angular js. any pointers? or a direction i should head?

I use mongodb as a db store

Share Improve this question asked Feb 4, 2013 at 21:30 AdamAdam 841 silver badge4 bronze badges 2
  • 1 This is a pretty broad/vague question. Certainly you can find examples around the web. If you have some code you're having an issue with or something more specific, that would make a better question. – Ben Lesh Commented Feb 4, 2013 at 21:41
  • why do you want to do filtering on client side mongo db provide very fast filtering of its own – Ajay Singh Beniwal Commented Feb 5, 2013 at 6:50
Add a ment  | 

1 Answer 1

Reset to default 5

Here is the example using mongolab: http://jsfiddle/CLVpf/2/

You can just $watch the query variable to construct query URL, and call query() against the ngResource instance.

$scope.$watch('search', function (key) {
    var q = null;
    if (key) {
        q = {
            q: '{name:{$regex:"' + key + '"}}'
        };
    }
    $scope.projects = Project.query(q);
});

Here Project is the ngResource instance.

本文标签: javascriptAngular js server side filter and paginationStack Overflow