下面是我的示例代码,通过检查项目是否已经存在,将其推入VacanciesWithSavedSearches数组。检查在推送项目之前是否存在属性值
if ($scope.VacanciesWithSavedSearches.indexOf(value) == -1) {
$scope.VacanciesWithSavedSearches.push({
type: "Saved Searches",
title: value.title,
value: value.id
});
}
如何修改我上面用实际属性值替换的indexOf,如添加项目到列表VacanciesWithSavedSearches如果列表中不包含其他item.id = 123
你确定你需要'VacanciesWithSavedSearches'数组?如果你正在查找唯一的ID,那么对象或地图看起来会更好。 – spanky