loda sh _.intersectionBy не работает в функции обратного вызова - PullRequest
0 голосов
/ 07 апреля 2020

Я пытаюсь использовать метод loda sh intersectionBy через "id", используя функцию обратного вызова angular js typcript, но по какой-то причине он не работает с id. Как мы можем пересечь по id с функцией обратного вызова.

Здесь моя попытка.

private filterOutputRelationFn: Function; // created declaration

 this.filterOutputRelationFn = _.intersectionBy; // defined

console.log(this.filterOutputRelationFn([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'));  // Not working by id

Expected result:
// => [{ 'x': 1 }]

таким же образом, если я пытаюсь с "_.intersection" Это работает. В чем может быть проблема в приведенном выше сценарии.

 private filterOutputRelationFn: Function; // created declaration

 this.filterOutputRelationFn = _.intersection; // assigned

console.log(this.filterOutputRelationFn([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }]));  // It works

Expected result
// => [{ 'x': 1 }]
...