1. #1
    Ext User
    Join Date
    Aug 2010
    Posts
    4
    Vote Rating
    0
    edrmp is on a distinguished road

      0  

    Default 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

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,828
    Vote Rating
    609
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    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!

  3. #3
    Ext User
    Join Date
    Aug 2010
    Posts
    4
    Vote Rating
    0
    edrmp is on a distinguished road

      0  

    Default


    Great evant!

    Working fine now!

    Thank you.

  4. #4
    Touch Premium Member
    Join Date
    May 2010
    Location
    The Netherlands
    Posts
    46
    Vote Rating
    0
    axxerion is on a distinguished road

      0  

    Default


    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

  1. Localstorage or SqLite
    By ssdesign in forum Sencha Touch 1.x: Discussion
    Replies: 6
    Last Post: 28 Oct 2010, 1:19 AM
  2. Load store from localStorage
    By stefx in forum Sencha Touch 1.x: Discussion
    Replies: 7
    Last Post: 1 Sep 2010, 1:58 AM
  3. Localstorage question
    By ssdesign in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 28 Jul 2010, 9:16 PM

Thread Participants: 2

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi