javascript - VueJS: Filter through objects in an array - Stack Overflow

I'm working on a vue-js problem.I got an data-element (object) called items. I am looping through

I'm working on a vue-js problem.

I got an data-element (object) called items. I am looping through these products and display a dropdown with a list of the items.

Now I would like to show only those items who have a value in an array thats called "Watt" and a Title.

This is an example item of items:

Item

-Title

-Date

-Specifications [Array]

-- [0] Name: "Watt"

-- [0] Value: 5

-- [1] Name: "Weight"

-- [1] Value: 100

Any idea how to solve this?

I'm working on a vue-js problem.

I got an data-element (object) called items. I am looping through these products and display a dropdown with a list of the items.

Now I would like to show only those items who have a value in an array thats called "Watt" and a Title.

This is an example item of items:

Item

-Title

-Date

-Specifications [Array]

-- [0] Name: "Watt"

-- [0] Value: 5

-- [1] Name: "Weight"

-- [1] Value: 100

Any idea how to solve this?

Share Improve this question asked Feb 15, 2017 at 12:05 SPQRIncSPQRInc 2184 gold badges37 silver badges81 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

This is not VueJS specific. In Javascript you filter an array with Array#filter. Example:

items = items.filter(function(item) {
    return item.Title && item.Specifications.some(function(specification) {
         return specification.Name === "Watt";
    });    
});

To understand this have a look at Array#some and Array#filter functions. The above code basically filters the items array by the condition that the item has at least one (some) element in the Specification array where the Name is "Watt" and has a title.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745139247a4613352.html

相关推荐

  • javascript - VueJS: Filter through objects in an array - Stack Overflow

    I'm working on a vue-js problem.I got an data-element (object) called items. I am looping through

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信