В настоящее время у меня возникла проблема с пользовательским фильтром.У меня есть массив объектов CVE, называемых «cves» (в моей области видимости), и для каждого элемента я генерирую строку tr в таблице, используя ng-repeat.
Вот глобальная структура CVE:
cve: {
id: integer,
cve: string,
summary: text,
description: text,
cvss:{
score: float,
vector: string
}
}
Вот мой HTML-код
<input type='text' ng-model='searchField'/>
....
<tr ng-repeat="cve in cves | cveFilter:[ad_filters, searchField] as filtered_cves"
ng-if="cves.length > 0">
<td colspan="7" class="no-padding">
//printing infos in a custom directive
</td>
</tr>
....
Вот мой фильтр:
.filter('cveFilter', function () {
return function (cves, params) {
console.log(cves);
let items = {
ids: params[0],//the ids (array of ids)
text: params[1],//the text
filtered_cves: []//the output
};
// for each cve, if its ID is in items.ids
// AND if one of the property of the CVE match with items.text
// push it to items.filtered_cves
cves.forEach(function (cve) {
if (
items.ids.includes(cve.id) &&
(
cve.cve.match(items.text) ||
cve.summary.match(items.text) ||
cve.description.match(items.text) ||
cve.cvss.score.match(items.text) ||
cve.cvss.vector.match(items.text)
)
) {
items.filtered_cves.push(cve)
}
});
return items.filtered_cves;
};
});
Моя проблема в следующем: мой фильтр работает, он сохраняеттолько соответствующие CVE, но каждый CVE отображается в двух экземплярах.Это означает, что если в моем массиве $ scopes.cves будет 6 cves, в моей html-таблице будет 12 строк.
Это мой первый пользовательский фильтр, но я считаю, что это глупая ошибка.
Вы знаете, где я потерпел неудачу?
Заранее благодарю,