如何在React Redux中合并数组值,例如具有相同ID的SQL连接?

时间:2018-09-26 06:19:51

标签: reactjs redux

const initialState = {

booksData: [
{"Code":"BK01","price":"5"},
{"code":"BK02","price":"30"},
] 
author: [
{"Code":"BK01","name":"Ravi"},
{"code":"BK02","name":"Suresh"},
] 

};

combinedBooksData:[

{"Code":"BK01","price":"10","name":"Ravi"},
{"code":"BK02","price":"25","name":"Suresh"},

]

1 个答案:

答案 0 :(得分:0)

这应该可以解决问题

var mergedList = _.map(initialState.booksData, function(item){
    return _.extend(item, _.findIndex(initialState.author, { id: item.Code }));
});