简体   繁体   English

用角度过滤对象

[英]filtering objects with angular

I am trying to filter an object in angular controller.我正在尝试过滤角度控制器中的对象。 I always get undefined as a result in my variable and cant figure out why.由于我的变量中的结果,我总是未定义并且无法弄清楚原因。 I made a screenshot of my console.我制作了我的控制台的屏幕截图。 where you can see the object and the filter function.您可以在其中看到对象和过滤器功能。 What am i doing wrong?我究竟做错了什么?

OK here is the main part of the function. OK 这里是函数的主要部分。 Am getting back undefined, so it have to do something with the way am using the filter?:返回未定义,所以它必须对使用过滤器的方式做些什么?:

this.update_lead_status = function (lead, sts) {

            this.status = $filter('filter')(leads.leads_status, { ls_id: 3 });

        };

在此处输入图片说明

The json object which is provided by a service:服务提供的 json 对象:

leads.leads_status [
{ls_id: 1, ls_class: 'lost', ls_name: 'Status1'},
{ls_id: 2, ls_class: 'lost2', ls_name: 'Status2'}
]

I am trying to get back the object item based on the ls_id and asign the variables one by one to my scope!我正在尝试根据 ls_id 取回对象项并将变量一一分配给我的范围! Thanks谢谢

I had to add a [0] to the end of my filter function, like this:我必须在过滤器函数的末尾添加一个 [0],如下所示:

var status = $filter('filter')(leads.leads_status, { ls_id: sts })[0];

Now it works fine for me!现在它对我来说很好用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM