![](/img/trans.png)
[英]How to display specific number of divs depending on width in react.js?
[英]How to get only the specific variation data to be display in react.js
如果要获取属性的子集,可以使用数组过滤器方法。 例如:
const res = {
data: {
VariationList: {
Attribute: {
Weight: 1,
Length: 2,
Width: 3,
Hook: 4
}
}
}
};
function getProductAttributes(data, filterList = []) {
const entries = Object.entries(data.VariationList.Attribute);
if (!filterList.length) return entries;
return entries.filter((attr) => filterList.includes(attr[0]));
}
let output = getProductAttributes(res.data);
console.log(output); // [ [ 'Weight', 1 ], [ 'Length', 2 ], [ 'Width', 3 ], [ 'Hook', 4 ] ]
output = getProductAttributes(res.data, ['Weight', 'Length']);
console.log(output); // [ [ 'Weight', 1 ], [ 'Length', 2 ] ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.