1
나는이처럼 보이는 URL에서 다시 배열을 받고 있어요 :그룹은 객체 배열 밑줄 JS
이[
{
id : 1,
product_id : 101,
price_new : 80,
price_old : 90
},
{
id : 2,
product_id : 101,
price_new : 80,
price_old : 90
},
{
id : 3,
product_id : 102,
price_new : 80,
price_old : 90
},
]
I가,이 변환하고 싶습니다 :
[
{
product_id : 101,
offers : [
{
id: 1
price_new : 80,
price_old : 90
},{
id: 2
price_new : 80,
price_old : 90
}]
},
{
product_id : 102,
offers: [{
id : 3,
price_new : 80,
price_old : 90
}]
},
]
사람은 방법을 알고 밑줄 js를 사용하여이 작업을 완료 하시겠습니까? 우리가 전체 프로젝트에서 사용하고 있기 때문에 밑줄을 사용하여 솔루션을 얻고 싶습니다. 그러면 더 깨끗해 보입니다 ...
나에게 잘 보이는! 고맙습니다! –
업데이트를 확인하십시오 (수락 할 때 업데이트가 작동 했음). 밑줄 메서드를 사용하는 것이 훨씬 더 깨끗합니다. – ssube
'var arranged = _.map (_ groupBy (data, 'product_id'), function (item, key)) { return { product_id : key, 은 다음과 같은 기능을 제공합니다. _ map (item, _.partial (_. 생략, _, 'product_id')) } });' – lemieuxster