如何从数组b获取特定属性。要过滤的属性在数组a。
中使用下划线是否有更简单的方法。
#contactdetails-right{float: right;}
现在如果使用下划线我怎样才能得到以下结果
var a = [{
name: "code"
}, {
name: "barcode"
}, {
name: "status",
type: "button"
}];
var b = [{
id: 1,
code: 10,
barcode: "121212",
status: "success",
amount: "10",
available: true
}, {
id: 1,
code: 10,
barcode: "121212",
status: "success",
amount: "10",
available: true
}];
答案 0 :(得分:1)
(function( property, x, y ) {
var filters = _.pluck( x, property );
var filter = function( obj ) {
return _.pick( obj, filters );
};
return _.map( y, filter );
})( 'name', a, b );
答案 1 :(得分:1)
var filters = _.pluck(a, 'name');
var c = _.map(b, function(el) {
return _.pick(el, filters);
});