1. #1
    Sencha User
    Join Date
    Feb 2011
    Location
    Düsseldorf, Germany
    Posts
    557
    Answers
    33
    Vote Rating
    31
    Kurt001 has a spectacular aura about Kurt001 has a spectacular aura about

      0  

    Default Answered: Localstorage access first()

    Answered: Localstorage access first()


    Hi there,

    I want to access the first item in a localstorage.

    Here is my model:

    Code:
    Ext.define('AppData', {
        extend: 'Ext.data.Model',
        config: {
            identifier: 'uuid',
            proxy: { type: 'localstorage', id: 'appData' },
            fields: [{ 'id', 'name' }]
        }
    });
    Saving a record:

    Code:
    var myApp =Ext.create('AppData',{ name:'Ed Spencer' });
    myApp.save({
            success:function(ed){
                    console.log("Saved Ed! His ID is "+ ed.getId());
            }
    });
    
    The id is something like ext-record-1417

    Here is how I want to load the first record:
    Code:
    
    var app = Ext.ModelMgr.getModel('AppData');
    app.load(1, {
            success: function(app) {
                    console.log("Loaded app 1: " + app.get('name'));
            },
            failure: function() {
                    console.log("NOT loaded app 1");
            }
    });
    This always throws the failure.

    I tried to use the example from the official example http://docs.sencha.com/touch/2-0/#!/guide/models.
    But with the localstorage this does not work either.

    Any idea?

    Best

  2. var id=localStorage.getItem('personalData').split(',')[0];//<-pass the localstorage proxy id config.

  3. #2
    Sencha User
    Join Date
    Nov 2011
    Location
    England
    Posts
    135
    Answers
    11
    Vote Rating
    7
    george.m is on a distinguished road

      0  

    Default


    You could try something like this..

    myStore.getData().items[0]

  4. #3
    Sencha User
    Join Date
    Feb 2011
    Location
    Düsseldorf, Germany
    Posts
    557
    Answers
    33
    Vote Rating
    31
    Kurt001 has a spectacular aura about Kurt001 has a spectacular aura about

      0  

    Default without store

    without store


    Hi ,

    I do not have a store for the data.

  5. #4
    Sencha User
    Join Date
    Sep 2012
    Posts
    65
    Answers
    7
    Vote Rating
    1
    warrean is on a distinguished road

      0  

    Default


    I use this in my app with a Store too:

    Store:
    Code:
    ..
     config: {
            storeId: 'credentialsStore',
    ..
    and then when I need the model
    Code:
    var credentials = Ext.getStore('credentialsStore').first();
    credentials.get('name');

  6. #5
    Sencha User
    Join Date
    Feb 2011
    Location
    Düsseldorf, Germany
    Posts
    557
    Answers
    33
    Vote Rating
    31
    Kurt001 has a spectacular aura about Kurt001 has a spectacular aura about

      0  

    Default


    Quote Originally Posted by warrean View Post
    I use this in my app with a Store too:
    Thanks but again: I do not want to use a store. This is a simple update function. The old version had a store, but only used a single record. Now I want to import the data from that first record.

    I could create a store and destroy it right after the import, but I was wondering if there is a way without using a store.

  7. #6
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    what does first mean? you order by what?
    Code:
    model.load(id,config)
    id != index

    as you said
    The id is something like ext-record-1417
    so why you pass a count or index number?
    I write English by translator.

  8. #7
    Sencha User
    Join Date
    Feb 2011
    Location
    Düsseldorf, Germany
    Posts
    557
    Answers
    33
    Vote Rating
    31
    Kurt001 has a spectacular aura about Kurt001 has a spectacular aura about

      0  

    Default


    Quote Originally Posted by haduki View Post
    what does first mean? you order by what?
    Using a store I would receive this item with store.first().
    Anyways as there is only one item in the localstorage for that model, I would just need that one.
    Quote Originally Posted by haduki View Post
    so why you pass a count or index number?
    What else would you pass?

  9. #8
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    pass the id
    I write English by translator.

  10. #9
    Sencha User
    Join Date
    Nov 2011
    Location
    England
    Posts
    135
    Answers
    11
    Vote Rating
    7
    george.m is on a distinguished road

      0  

    Default


    I'm guessing it's because that id changes every time he uses the app as it is one automatically generated by Sencha. Can you not add your own id to it?

  11. #10
    Sencha User
    Join Date
    Feb 2011
    Location
    Düsseldorf, Germany
    Posts
    557
    Answers
    33
    Vote Rating
    31
    Kurt001 has a spectacular aura about Kurt001 has a spectacular aura about

      0  

    Default


    @haduki
    how do i find out the id?


    Quote Originally Posted by george.m View Post
    I'm guessing it's because that id changes every time he uses the app as it is one automatically generated by Sencha. Can you not add your own id to it?
    This is an update of the app. So the old app wrote the localstorage and now I want to load the localstorage in the model. If I write the id I would write a new record, which I could load afterwards.
    But for now I do not know the id (auto-generated by Sencha).

    so what I am doing for now is:
    Code:
            Ext.define('oldData', {
                extend: 'Ext.data.Model',
                config: {
                    identifier: 'uuid',
                    fields: [
                        {name: 'id', type: 'int'},
                        {name: 'oneOfManyValues'}
                    ],
                    proxy: {
                        type: 'localstorage',
                        id: 'personalData'
                    }
                }
            });
            var myStore = Ext.create('Ext.data.Store', {
                model: 'oldData',
                autoLoad: true
            });
            var oldData = myStore.first() ? myStore.first().getData() : null;
            Ext.StoreManager.remove(myStore);
    This will do the trick, but I was hoping to go without the store.

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar