我有一个带有JavaScript的get方法的泛型类,当我尝试访问我的方法时,当我多次使用此get方法嵌套时,对于从get方法获得的电子邮件值已经存在相同的结果。
这是我的通用方法。
var client = new HttpClient();
client.get(API_PRESTASHOP_END_POINT + '/customers', function(response) {
var response = JSON.parse(response);
var arrIndex = response.customers;
var i = 0;
for(idx in arrIndex) {
//console.log(idx + ':' + id); OK
var http = new HttpClient();
http.get(API_PRESTASHOP_END_POINT + '/customers/' + arrIndex[idx].id, function(res) {
//console.log(res); OK
var request = window.indexedDB.open("modullo", 1);
request.onsuccess = function(ev) {
db = ev.target.result;
var transaction = db.transaction(['customers'], 'readonly');
var objectStore = transaction.objectStore('customers');
var index = objectStore.index('email');
index.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
if(cursor) {
//console.log(cursor.key); cursor.continue(); OK
var object = JSON.parse(res);
var email = object.customer.email;
//console.log(cursor.key + ':' + email); NOT OK (email already the same email value)
//console.log(object);
if(cursor.key == email) {
//console.log(cursor.value.email + ':' + email); return;
//console.log(cursor.primaryKey); return;
var req = db.transaction(['customers'], 'readwrite').objectStore('customers').delete(Number(cursor.primaryKey));
req.onsuccess = function (event) {
i++;
console.log('The user already has a Prestashop account...');
console.log(i + ' deletion');
}
} else {
cursor.continue();
}
}
}
}
}, {"Output-Format": "JSON", "Authorization" : "Basic " + btoa(API_KEY_PRESTASHOP + ':' + API_KEY_PRESTASHOP)});
}
}, {"Output-Format": "JSON", "Authorization" : "Basic " + btoa(API_KEY_PRESTASHOP + ':' + API_KEY_PRESTASHOP)});
提前寻求帮助