-
23 Nov 2012 3:40 PM #1
Sencha Touch 2.0.1.1 Local Store not storing values
Sencha Touch 2.0.1.1 Local Store not storing values
Hi All,
I am trying to store in the local storage and its not getting stored
.
I need to store two values as state id and license type as 1 record and next time I will update it. So the store will always has 1 record like below.
I tried for the last 2 days and with different option but its not storing.Code:{ 'stateId': 'NJ', 'licenseType': 'BDL' }
Can someone please tell me what can be the problem in my code.
Note: I am trying to test is using Chrome browser.
Store Code
Model CodeCode:Ext.define("Sencha.store.TestParams", { extend: "Ext.data.Store", requires: [ "Ext.data.proxy.LocalStorage" ], config: { model: "Sencha.model.TestParam", autoSync: true, proxy: { type: 'localstorage', id: 'ezdt-test-params' } } });
Actual Code to saveCode:Ext.define("Sencha.model.TestParam", { extend: "Ext.data.Model", config: { idProperty: 'id', fields: [ { name: 'id', type: 'int' }, { name: 'stateId', type: 'string' }, { name: 'licenseType', type: 'string' } ] } });
Code I am using to retrieve the store value.Code:var modTestParamInitialValues = Ext.create("Sencha.model.TestParam", { id: 'ezdt', //Always Same as there will be only one record. stateId: strSelectedState, licenseType: strSelectedLicenseType }); storTestParams.add(modTestParamInitialValues); storTestParams.sync();
Always its printing as Not Set
I hope I give all the details. If you need any more details please let me know.Code:var storTestParams = Ext.getStore("TestParams"); console.log("storTestParams#####-->" + storTestParams); //storTestParams.load(); if(null != storTestParams) { var intTestParamCount = storTestParams.getCount(); if(intTestParamCount == 0) { console.log("Not Set"); } else { console.log("Set Correctly"); } } else { console.log("Set Correctly"); }
Thanks for your help.
Joseph
-
26 Nov 2012 3:31 AM #2
In your model, the ID field is set as an integer.
When you create a model, you set 'ezdt' as the ID. But 'ezdt' is not an int, but a String. Maybe that's the problem.
Try this in your model:
Do you use the developper tool in chrome? (Ctrl-Shift-I)Code:fields: [ { name: 'id', type: 'auto' }, { name: 'stateId', type: 'string' }, { name: 'licenseType', type: 'string' } ]
If not, you really should! Because in the "Resources" tab, you'll find all the Local Storage objects that are currently stored, and many other really helpfull features!
This is the way I store an object in my LocalStorage:
I'm not saying this is the way you have to store something in your localstorage, but this code just works fine for me.Code:console.log("Try to store something"); userstore = Ext.getStore('LocalStorageUserStore'); var model = new App.model.LocalStorageUser({ id: '1', user: "username", pwd: "password" }); var records = userstore.add(model); records[0].save(); userstore.sync(); var user = userstore.getAt(0).data.user; console.log(user); var pwd = userstore.getAt(0).data.pwd; console.log(pwd);
-
28 Nov 2012 7:54 AM #3
Error for the line records[0].save();
Error for the line records[0].save();
I use the same code and still I am getting the below error for the line records[0].save();

Can you please tell me what proxy you use in the model.
This is the code that I use to save the file.
Code:var now = new Date(); var noteId = (now.getTime()).toString() + (this.getRandomInt(0, 100)).toString(); var newNote = Ext.create("NotesApp.model.Note", { id: noteId, dateCreated: now, title: "Joseph", narrative: "Joseph Desc" }); var records = notesStore.add(newNote); records[0].save(); notesStore.sync();
Uncaught Error: [ERROR][NotesApp.controller.Notes#onSaveNoteCommand] You are trying to save a model instance that doesn't have a Proxy specified
-
28 Nov 2012 8:03 AM #4
This is the code:
Code:Ext.define( 'App.model.LocalStorageUser', { extend: 'Ext.data.Model', alias: 'widget.LocalStorageUser', config: { idProperty: 'id', fields: [ { name: "id", type: "auto" }, { name: "user", type: "string" }, {name: "pwd", type:"string"} ], proxy: { type: 'localstorage', id: 'users' } } });


Reply With Quote