deleteLinks.on('click', function(ev){
ev.preventDefault();
var currentHTML = $('.product');
var currentHTMLMap = $('.product').toArray().map(elm => [ $(elm).attr("data-id-product"), $(elm).attr("data-id-product-attribute") ]);
var deleteIndices = [];
$.ajax({
url: this.href,
type: "GET",
dataType: "html",
success: function(data) {
var newHTMLMap = $(data).find(".product").toArray().map(elm => [ $(elm).attr("data-id-product"), $(elm).attr("data-id-product-attribute") ]);
for(i = 0; i < currentHTMLMap.length; i++){
if (!(newHTMLMap.includes(currentHTMLMap[i]))) {
console.log("found mismatch for index " + i);
deleteIndices.push(i);
}
}
for(i = 0; i < deleteIndices.length; i++) {
currentHTML[deleteIndices[i]].remove();
}
}
});
});
我在变量中得到以下数据:
currentHTMLMap: 6,0,2,9,1,1
currentHTMLMap[0]: 6,0
currentHTMLMap[1]: 2,9
currentHTMLMap[2]: 1,1
newHTMLMap: 2,9,1,1
newHTMLMap[0]: 2,9
newHTMLMap[1]: 1,1