-
13 Sep 2010 12:47 PM #1
Load record from LocalStorage using Ext.ModelMgr
Load record from LocalStorage using Ext.ModelMgr
Hi,
I wondering if there are any way to load a record from LocalStorage with Ext.ModelMgr.
When I use Ext.ModelMgr.create, I successfully create and edit the record, using a form or using the console. However, when the object is already stored and is loaded from the store, the behavior is different, a new record, with the identifier "undefined" is created instead.
Also, If I create the record with Ext.ModelMgr, I can get the object with store.getById(1). But when the page is reloaded, no. Only store.getAt(0) appears to work in this case.
Some Code:
Code:Ext.regModel('Person', { fields: [ {name: 'name', type: 'string'}, {name: 'age', type: 'int'} ] }); store = new Ext.data.Store({ model: 'Person', proxy: { type: 'localstorage', id : 'personst' }//, //autoLoad: true }); store.read(); person = store.getAt(0); if(!person){ person = Ext.ModelMgr.create({name:"John", age:30}); store.add(person); store.sync(); } person.set("name", "John B.") store.sync()
So, I would like to know if I can load a record from the LocalStorage using Ext.ModelMgr. Or, if not, if I can bind the record obtained from the LocalStorage with the Model/ModelMgr anyway.
Any help would be appreciated.
Thanks
-
13 Sep 2010 6:13 PM #2
You need to give it some kind of id so it can refer to it again when the page loads:
Code:Ext.regModel('Person', { fields: [{ name: 'id', type: 'int' },{ name: 'name', type: 'string' }, { name: 'age', type: 'int' }] }); var store = new Ext.data.Store({ model: 'Person', proxy: { type: 'localstorage', id: 'personst', proxy: { idProperty: 'id' } } }); store.read(); person = store.getAt(0); if (!person) { console.log('creating'); person = Ext.ModelMgr.create({ id: 1, name: "John", age: 30 }, 'Person'); store.add(person); store.sync(); } person.set("name", "John B.") store.sync();Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
14 Sep 2010 6:26 AM #3
-
15 Sep 2010 10:46 AM #4
I am using 0.94... and that does not work for me.. my code is:
Ext.regModel('AxxerionList', {
idProperty: 'id',
fields: [
// id's
'id',
'objectNameId',
// basic info
'Field0',
'Field1',
'Field2',
'Field3',
'FieldIcon',
]
});
// here i create the store...
this.store = new Ext.data.Store({
model: 'AxxerionList',
proxy: {
type: 'localstorage',
id : 'temporalist1A'
}
});
this.store.read();
// i put some items inthere..
var itemsTemp = [];
....//create some items.
store.loadData(itemsTemp);
store.sync();
// I see in Chrome that a localstorage is created with the key="temporallist1A-<<id>>", where id is the idProperty... that is OK ...
// second time i do the following
this.store.read();
alert(this.store.getAt(0));
and the alert is given "undefined"....
Similar Threads
-
Localstorage or SqLite
By ssdesign in forum Sencha Touch 1.x: DiscussionReplies: 6Last Post: 28 Oct 2010, 1:19 AM -
Load store from localStorage
By stefx in forum Sencha Touch 1.x: DiscussionReplies: 7Last Post: 1 Sep 2010, 1:58 AM -
Localstorage question
By ssdesign in forum Sencha Touch 1.x: DiscussionReplies: 2Last Post: 28 Jul 2010, 9:16 PM


Reply With Quote