Right now getting an issue in displaying a IndexedDB objects. please some one help to do the progress in the same. in my case,once if i enable the offline image will display from dynamic cache but indexedDB looks empty objects. so that help me to display the image from the IndexedDB.here below is the code i have tried:
function createCard(data)
{
var asd = data;
$.each(asd, function(index, data) {
var template='<a href="viewexpense1.html class="expenseItem">\n\
<div class="itemReceipt">\n\
<img src="'+data.image+'">\n\
<span class="itemCategory"><img src="images/meals.png"></span>\n\
</div>\n\
<div class="expenseName singleLine">\n\
<h3>'+data.tittle+'<img src="images/sync.png"></h3>\n\
</div>\n\
<div class="clearfix"> </div>\n\
</a>';
$('#reportContent').append(template);
});
}
var url='https://pwa-cssi.firebaseio.com/ posts.json';
var networkDataReceived = false;
fetch(url)
.then(function(res)
{
return res.json();
})
.then(function(data)
{
networkDataReceived =true;
console.log('from web',data);
var dataArray=[];
for(var key in data)
{
dataArray.push(data[key]);
}
console.log(data)
createCard(dataArray);
});
if('caches' in window)
{
caches.match(url)
.then(function(response)
{
if(response)
{
return response.json();
}
})
.then(function(data)
{
console.log('From cache',data);
if(!networkDataReceived)
{
var dataArray=[];
for(var key in data)
{
dataArray.push(data[key]);
}
createCard(dataArray)
}
})
}
if('indexedDB' in window)
{
console.log('123');
readAllData('posts')
.then(function(data){
console.log('456');
if(!networkDataReceived)
{
console.log('From cache s',data);
var dataArray=[];
createCard(dataArray);
});
}
and i have code like this for read allData function
function readAllData(posts)
{
console.log('asdasdasd');
return dbPromise
.then (function(db){
var tx=db.transaction('posts','readonly');
var store=tx.objectStore('posts');
console.log('asdasdasd123');
return store.getAll();
});
}
please some one help me.i got struck for since last 2 days