我有一個JSON對象如下如何使JSON對象從具有唯一值JSON對象的元素在下劃線JS
[
{
"MerchantName": "Fashion and You",
"BrandList": " Nike, Fila",
"MerchantImage": "Fashion-You-medium.jpeg"
},
{
"MerchantName": "Fashion and You",
"BrandList": " Levis, Fasttrack, Fila",
"MerchantImage": "Fashion-You-medium.jpeg"
},
{
"MerchantName": "ebay",
"BrandList": "Nokia,HTC,Samsung",
"MerchantImage": "ebay.jpeg"
},
{
"MerchantName": "amazon",
"BrandList": "Apple,Dell,Samsung",
"MerchantImage": "amazon.jpeg"
},
{
"MerchantName": "amazon",
"BrandList": " pepe jeans, peter england, red tape",
"MerchantImage, Fila": "amazon.jpeg"
}
]
我需要用獨特的BrandList JSON對象,如下面的下劃線。
[{"Nike"}, {"Fila"},{"Levis"}, {"Fasttrack"},{"Nokia"}, {"HTC"},{"Samsung"}, {"pepe jeans"}, {"peter england"},{"red tape"}]
我可以如下獲取數據而不是上述格式,品牌必須是唯一的。
brands = [{brand:"Nike",status:false}, {brand:"Fila",status:false}, {brand:"Levis",status:false},{brand:"Fasttrack",status:false}, {brand:"Nokia",status:false},{brand:"HTC",status:false}, {brand:"Samsung",status:false} ]
'_.pluck()'很容易處理 - 在Underscore文檔中查找 – Bojangles
您的問題真的是關於JSON還是關於在JavaScript中處理數據?另請注意,您所需的結果不是有效的JSON。 –
當我使用_.pluck()即時獲取數據爲[「耐克,菲拉」,「萊維斯,Fasttrack,菲拉」] –