Question

I have code bellow

var jsonData='{              
           "results":[            
              {                    
                "id":"460",         
                "name":"Widget 1",   
                "loc":"Shed"          
              },{                    
                "id":"460",         
                "name":"Widget 2",   
                "loc":"Shed"          
              },{                    
                "id":"460",         
                "name":"Widget 2",   
                "loc":"Shed"          
              },{                    
                "id":"460",         
                "name":"Widget s",   
                "loc":"Shed"          
              },{                      
                "id":"461",             
                "name":"Widget 2",       
                "loc":"Kitchen"           
              }]                           
        }';

    var jsObj=JSON.parse(jsonData);

Now I am going to insert data in jsobj, and data should reflect in indexed db aswell, is it possible that I can sync javascript object with Indexed DB

Était-ce utile?

La solution

If you only want to store that single list in persistent storage I would recommend you to use Local Storage instead of IndexedDB.

Here is a sample code which shows you how to store and retrieve your data:

// Put the object into storage
localStorage.setItem('jsonData', JSON.stringify(jsonData));

// Retrieve the object from storage
var retrievedObject = JSON.parse(localStorage.getItem('jsonData'));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top