Feedback on http://docs.angularjs.org/#!/api/angular.Array.filter

126 views
Skip to first unread message

Asutosh Dash

unread,
Jun 9, 2011, 11:41:33 PM6/9/11
to angular
Hi there, 


I have an JSON array:

phones = [{"name": "Nexus S",
                  "snippet": "Fast just got faster with Nexus S.","specs":[{"camera": "15px",
                  "FFC": "No"}]},
                 {"name": "Motorola XOOM with Wi-Fi",
                  "snippet": "The Next, Next Generation tablet.","specs":[{"camera": "11px",
                  "FFC": "No"}]},
                 {"name": "MOTOROLA XOOM",
                  "snippet": "The Next, Next Generation tablet.","specs":[{"camera": "15px",
                  "FFC": "No"}]},
           {"name": "MOTOROLA XOOM",
                  "snippet": "The Next, Next Generation tablet.","specs":[{"camera": "15px",
                  "FFC": "No"}]}];

Presently I am able to filter phones on basis of name, snippet and specs, however I am not able to search on basis of camera, can anyone explain ho to do that.


Regards
Asutosh

Vojta Jina

unread,
Jun 10, 2011, 9:27:56 AM6/10/11
to ang...@googlegroups.com
Use function as filter argument:

angular.Array.filter(phones, function(p) {
return p.specs[0].camera == '15px';
});

angular.Array.filter(phones, function(p) { for (var i = 0; i < p.specs.length; i++) { if (p.specs[i].camera == '15px') return true; } return false; });

V.

Asutosh Dash

unread,
Jun 16, 2011, 6:17:25 AM6/16/11
to ang...@googlegroups.com
Thanks for your replay, however want to know where should I use this
function, whether in the controller or in the view.

>
> angular.Array.filter(phones, function(p) { for (var i = 0; i <
> p.specs.length; i++) { if (p.specs[i].camera == '15px') return true; }
> return false; });
>
> V.
>
> --
> You received this message because you are subscribed to the Google Groups
> "angular" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/1mFUr__IUh0J.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.
>

Vojta Jina

unread,
Jun 16, 2011, 10:07:27 AM6/16/11
to ang...@googlegroups.com
You need to unit test this, so the answer is: in controller.
You can't define function in template..
V.

Asutosh Dash

unread,
Jun 17, 2011, 3:32:06 AM6/17/11
to ang...@googlegroups.com
Thanks for your help,
I made the changes as you suggested, it worked nicely.

Asutosh

> --
> You received this message because you are subscribed to the Google Groups
> "angular" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/angular/-/aYL2fPtUYEIJ.

Vojta Jina

unread,
Jun 17, 2011, 12:02:47 PM6/17/11
to ang...@googlegroups.com
Glad it helped...
V.
Reply all
Reply to author
Forward
0 new messages