products: [
{
id: 190,
goodsId: 27,
proNo: "HUAWEI0A01_1",
spec: null,
storeNums: null,
warningLine: null,
marketPrice: 3199,
sellPrice: 3199,
costPrice: 3199,
weight: null,
specsKey: ";2:7;8:74;10:77;"
},
{
id: 191,
goodsId: 27,
proNo: "HUAWEI0A01_2",
spec: null,
storeNums: null,
warningLine: null,
marketPrice: 2999,
sellPrice: 3199,
costPrice: 2999,
weight: null,
specsKey: ";2:7;8:74;10:78;"
},
{
id: 192,
goodsId: 27,
proNo: "HUAWEI0A01_3",
spec: null,
storeNums: null,
warningLine: null,
marketPrice: 3199,
sellPrice: 3199,
costPrice: 3199,
weight: null,
specsKey: ";2:9;8:74;10:77;"
},
{
id: 193,
goodsId: 27,
proNo: "HUAWEI0A01_4",
spec: null,
storeNums: null,
warningLine: null,
marketPrice: 2999,
sellPrice: 3199,
costPrice: 2999,
weight: null,
specsKey: ";2:9;8:74;10:78;"
}
]
如上代码,如何通过specsKey拿到其他的参数?例如id或者sellPrice
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
var data,specsKey=XXX;
products.map(function(v){
if(v.specsKey==specsKey){
data=v;
}
})
这是一个json数据格式,取products的下id值方式:
把取得的相关参数和specsKey对比再取到对应的值就行了。