I have a promise that seemed to work before but not now.
I think I have everything in place but after the .get is called, it never gets to the for loop.
It jumps to the end and out of the promise, then back to the return (inside the .get) then to the resolve and then out.
If there were an error, it should have jumped to the catch but didn't, so how does it miss the for loop?
Here is the code:
function readAllImagesFromPouch(id, imageDisplay) {
return new Promise(function (resolve, reject) {
var startElement = document.getElementById(imageDisplay);
var image = "";
// Get all attachments for this id
DB_TaskImages.get(id, { attachments: true }).then(function (doc) {
for (var key in doc._attachments) {
DB_TaskImages.getAttachment(doc._id, key).then(function (blob) {
var img = document.createElement('img');
blob = resizeImage(blob, "100", "60");
var url = URL.createObjectURL(blob);
img.src = url;
//alert(img.outerHTML);
//startElement.appendChild(img);
$(startElement).append("<div class='row' style='border:1px solid black'><div class='col-xs-10'>" +
img.outerHTML +
"</div>" +
"<div class='col-xs-1' style='padding-top:20px'>" +
"<img src='../Images/delete.png' alt='Delete' class='taskimage'>" +
"</div></div>"
);
return;
}).catch(function () {
console.log("No attachment for doc._id: " + doc._id + " and key: " + key);
})
}
return;
}).then(function () {
resolve();
}).catch(function (err) {
console.log("Image not there for id: " + id);
showMsg("Image not there for id: " + id);
reject(err);
})
}); // end of promise
}
And it is called from this code:
readAllImagesFromPouch("006", "divImages").then(function () {
}).catch(function (err) {
console.log("In catch for readAllImagesFromPouch with err: " + err);
})
Thanks,
Tom