1. #1
    Sencha User
    Join Date
    Mar 2012
    Location
    Tunisia
    Posts
    74
    Vote Rating
    0
    zied jouini is on a distinguished road

      0  

    Default Unanswered: LocalStorage

    Unanswered: LocalStorage


    Salam all. i'm tring to test a local storage. i found a code here
    http://miamicoder.com/2011/writing-a...cation-part-4/
    i modified the code above to be compatible with my app, so i divide it to 4 files: first the store file:

    Code:
    Ext.regStore('testStore', {
     
        model: 'Note',
        sorters: [{
                    property: 'date',
                    direction: 'DESC'
                }],
                proxy: {
                    type: 'localstorage',
                    id: 'notes-app-store'
                },
                getGroupString: function (record) {
                    if (record && record.data.date) {
                        return record.get('date').toDateString();
                    } else {
                        return '';
                    }
                }
    });


    second: model file:

    Code:
    Ext.regModel('Note', {
                fields: ['title','narrative']
            });


    third file is the view which i want to see my notes loaded from the local store :
    Code:
    App.views.notelist = Ext.extend(Ext.List, {
       
    store: 'testStore',
    grouped: true,
    emptyText: '<div style="margin:5px;">No notes cached.</div>',
    
    
    itemTpl: '<div class="list-item-title">{title}</div>' +
             '<div class="list-item-narrative">{narrative}</div>',
    
    
    listeners: {
                'render': function (thisComponent) 
                   {
                   thisComponent.getStore().load();
                   }
                }
    });
    Ext.reg('notelist', App.views.notelist);
    and the fourth file is the view which i insert information to be saved
    Code:
    App.views.NoteView = Ext.extend(Ext.Panel, {
    scroll: 'vertical',
    items: [{
     xtype: 'formpanel',
     id: 'form',
     cls : 'form',
     
        items: [
            
            {
               xtype: 'fieldset',
               title: 'Note',
            },
            {
                xtype: 'textfield',
                id : 'Titre',
                label: 'Titre'
            },
    
    
            {
                xtype: 'textareafield',
                id: 'narr',
                label: 'Corp',
            },
    
    
            {
                xtype: 'button',
                flex: 1,
                margin: 10,
                text: 'Enregistrer', 
                handler: function()
                       {
               alert ("begin");
               var titre = Ext.getCmp("Titre").getValue();
               var body = Ext.getCmp("narr").getValue();
               var NS = App.views.notelist.getStore();
               
               NS.add({title: titre},
                      {narrative: body});
      
               NS.sync();
               App.views.notelist.refresh();
               alert ("end");
                       }
            }
        ]
    
    
    }]
        
    });
    Ext.reg('NoteView', App.views.NoteView);
    but it doesn't work. i don't know where is the mistake (the add in the store dont work)... can anyone help me ? ? thank youu


    Last edited by zied jouini; 22 Apr 2012 at 12:15 PM. Reason: modification

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,714
    Vote Rating
    438
    Answers
    3113
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    What do you mean it doesn't work? What doesn't work?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Location
    Tunisia
    Posts
    74
    Vote Rating
    0
    zied jouini is on a distinguished road

      0  

    Default


    SALAM.
    the add don't work.
    Code:
    
            }
    
    
        xtype: 'button',
                flex: 1,
                margin: 10,
                text: 'Enregistrer', 
                handler: function()
                       {
               alert ("begin");
               var titre = Ext.getCmp("Titre").getValue();
               var body = Ext.getCmp("narr").getValue();
               var NS = App.views.notelist.getStore();
               
               NS.add({title: titre},
                      {narrative: body});
      
               NS.sync();
               App.views.notelist.refresh();
               alert ("end");
                       }
            }
    in this section of the code, the first alert appear ( alert ("begin")) but not the second (alert ("end")) and when i return to the view i don't see the new note

  4. #4
    Sencha User
    Join Date
    Aug 2011
    Location
    Belgium
    Posts
    29
    Vote Rating
    3
    Answers
    4
    gamevampy is on a distinguished road

      0  

    Default


    Maybe the next works:
    Code:
    NS.add({title: 'titre', narrative: 'body'});