[英]How to place these 2 arrays inside separate objects and push to the main array in JS?
我有 2 个过滤数组:
productsByCategory,
productsByTag
所以我需要得到以下结构:
this.filteredProducts = [{
type: 'Category'
products: productsByCategory // it's array
}, {
type: 'Tag'
products: productsByTag // it's array
}]
所以这应该是最终的结果。 我正在使用 Vue.js 和 lodash。 如何以优雅的方式实现这一目标?
如果您说出该结构背后的意图,则可以给出一个很好的直接答案,否则您只能使用一种方法来完成它。
{
data() {
return {
productsByCategory: [],
productsByTag: [],
filteredProducts: []
};
},
methods: {
groupProducts() {
this.filteredProducts.push({
type: "Category",
products: this.productsByCategory
});
this.filteredProducts.push({
type: "Tag",
products: this.productsByTag
});
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.