我有一个看起来像这样的数组:
this.firstArray = [{
"activityCode": "10",
"activityDisplayname": "Evidencija",
"smoduleCode": "UOM_RECORD_COMPONENT",
"label": "Evidencija",
"invalid": false,
"component": "VpnEvidencijaUslugeComponent",
"icon": "fa fa-puzzle-piece puzzle",
"disabled": false
}, {
"activityCode": "11",
"activityDisplayname": "Pregled",
"smoduleCode": "UOM_VIEW_COMPONENT",
"label": "Pregled",
"invalid": false,
"component": "OrderOverviewComponent",
"icon": "fa fa-check-circle circle",
"disabled": false
}, {
"activityCode": "12",
"activityDisplayname": "Provjera",
"smoduleCode": "UOM_CHECK_COMPONENT",
"label": "Provjera",
"invalid": false,
"component": "ValidationComponent",
"icon": "fa fa-check",
"disabled": true
}]
我有其他数组有一些特定的值,但结构与第一个相同。现在我想要的是返回两个数组中具有相同activityDisplayname
的对象数组。我试过这样的事情,但这是固定的activityDisplayname
let item = this.confing.filter(function(item) {
return item['activityDisplayname'] == 'Provjera';
});
现在我需要改变这个' Provjera'与第二个数组。有什么建议吗?
我创建了方法isCommon():
isCommon(ac:string){
for(var i = 0; i < this.confing.length; i++) {
if (this.confing[i]['activityDisplayname'] == ac) {
return this.confing[i];
}
}
console.log(this.confing,'sta je nasao')
}
然后我有了这个:
if(this.confing[this.active]['newOrder']){
let item = this.confing.filter(function(item) {
array = this.isCommon(item['activityDisplayname']);
});
但我得到错误:
财产&#39;是共同的&#39;类型&#39; void&#39;
上不存在
答案 0 :(得分:0)
我建议使用https://lodash.com/docs/4.17.4#intersectionBy
let arr = _.intersectionBy(arr1, arr2, 'activityDisplayname');