2016-03-21 19 views
0

Bir dizi görüntü içeren bir nesnem var (yalnızca kimlikleri). https://jsbin.com/pamofudisa/edit?html,js,console,outputBir nesneyi lodash kullanarak başka bir nesneyle genişletme

: Bu benim kodudur

var extendedListOfImages = { 
    "number-items": 30, 
    "pageCount": 0, 
    "ids": { 
    0: {"id": "image1", "author": "Marc", "size": "40kb"}, 
    1: {"id": "image2", "author": "Anthony", "size": "60kb"} 
    } 
}; 

:

var images = { 
     "image1": { 
     "author": "Marc", 
     "size": "40kb" 
     }, 
     "image2": { 
     "author": "Anthony", 
     "size": "60kb" 
     }, 
     "image3": { 
     "author": "Anthony", 
     "size": "60kb" 
     } 
    }; image2, 
    ] 

Onlara böyle hepsi çok sahip şey birleştirmek istiyorum:

var listOfImages = { 
     "number-items": 30, 
     "pageCount": 0, 
     "ids": { 
     0: "image1", 
     1: "image2" 
     } 
    }; 

Ben de resim koleksiyonu var

cevap

0

Yeni takmak için, mümkünse daha iyi bir çözümü takdir ediyorum. Şu anda Çözümümün: jsbin içinde

var listOfImages = { 
    "number-items": 30, 
    "pageCount": 0, 
    "ids": { 
    0: "image1", 
    1: "image2" 
    } 
}; 
var images = { 
    "image1": { 
    "author": "Marc", 
    "size": "40kb" 
    }, 
    "image2": { 
    "author": "Anthony", 
    "size": "60kb" 
    }, 
    "image3": { 
    "author": "Anthony", 
    "size": "60kb" 
    } 
}; 

myIds = _.keyBy(listOfImages.ids); 
_.map(myIds, function(key, value){ 
    myIds[key]= images[key]; 
}); 
listOfImages.ids=myIds; 
console.log(listOfImages); 

kodu: https://jsbin.com/qesuyewuza/1/edit?html,js,console,output

İlgili konular