Reputation: 1140
Using sencha touch, I want to store my array list data in localStorage as shown in image.
onStore refresh function as shown in image below
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.
Upvotes: 0
Views: 2691
Reputation: 3211
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.
Upvotes: 1
Reputation: 71
you can store full object but if you just want to store subjects then you need to create new model. define a model for storing subjects or you can store the full object you are getting.
Ext.define('Demo.model.Subjects', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'id', type: 'int' },
{ name: 'Subjects', type: 'auto' }
]
}
});
define a local store
Ext.define('Demo.store.MySubjectLocalStore', {
extend: 'Ext.data.Store',
config: {
storeId: 'mySubjectLocalStore',
model: 'Demo.model.Subjects',
autoLoad: true,
clearOnPageLoad: true,
proxy: {
type: 'localstorage',
id: 'demo-mySubjects-local-store'
}
}
});
to store data in local store
var subjectsLocal = Ext.getStore('mySubjectLocalStore');
//loop to get your subjects array from main Object then add each array to localstore
//loop start
var subjects = //get it from parent object inside loop
var subjectsModel = Ext.create('Demo.model.Subjects', {
Subjects : subjects,
id: //use integer so that you can get by this id when you retrive it
});
subjectsLocal.add(subjectsModel);
//loop End
subjectsLocal.sync();
Upvotes: 0