Search code examples
javascriptsencha-touchsencha-touch-2local-storagesencha-architect

Store array Data Object in localStorage using sencha touch


Using sencha touch, I want to store my array list data in localStorage as shown in image.

enter image description here

onStore refresh function as shown in image below

enter image description here

I stored simple data as Like Date, Id, Name in LocalStorage on BookStore refresh function. But could not find the way to store arrayObject directly to localStorage.


Solution

  • I am not sure i understand your question completely..

    If you want store javascript object in local Store, you can do it by converting javascript object into string using JSON.stringify() method.

    var testString = JSON.stringify(testObj); //Converts testObject to Json string.
    localStorage.testString = testString; // Stores testString into local storage.
    

    You can get testString from local storage and convert it into javascript object by

    var testObj = JSON.parse(localStorage.testString);
    

    Or you can use

    Ext.encode(); // Encodes an Object, Array to String.
    
    Ext.decode(); // Decodes (parses) a JSON string to an object.