我有两个数组:
//list elements from html
var list = document.querySelectorAll('#pres-list-ul li');
//list of retrieved objects from api
var objects = self.retrievedItems;
为了提高效率(无需重新渲染相同的数据,除非您刷新),列表内容保存在html文件中。
如果在检索到的对象中不存在一个列表项,则希望从html中删除它。
我知道以下代码大致上是这样的,但我无法解决它。
//I need to compare the id? For that another loop - which will run hundreds and thousands of time?
for(var j = 0; j < objects.length; j++) {
if(objects.indexOf(list[i]) === -1) {
//false
} else {
//true
}
}
场景:
list: 57 //local
objects: 56 //online
找到列表中的额外值并将其删除。
列表:
<li id="item-5756" data-category="" data-group="" data-created="" data-author=""></li>
对象:
0: {
id: //
title: //
description //
// ...
}
1: {
//...
}
list
和objects
的示例。 - Martin Gottweis