1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    42
    Vote Rating
    0
    bagusflyer is on a distinguished road

      0  

    Default Can't save into store

    Can't save into store


    After solving a few problems, at last I can see my view but I came across another problem: I can't save my data (model) into a store. Here is my code:

    Code:
            var currentUser= this.profileView.getRecord();
            this.profileView.updateRecord(currentUser);
    
    
            var errors = currentUser.validate();
            if (!errors.isValid()) {
                currentUser.reject();
                Ext.Msg.alert('Wait!', errors.getByField('name')[0].message, Ext.emptyFn);
                return;
            }
    
    
            // save user profile to data store
            var store = this.getStore('App.store.MyProfile');
            if (null == store.findRecord('id', currentUser.data.id)) {
                store.add(currentUser);
            } else {
                currentUser.setDirty();
            }
    Almost the same code running in Sencha Touch 1.1 has no problem. But failed at Sencha Touch 2. The error message is:

    Uncaught TypeError: Cannot call method 'create' of undefined

    It's either in this.profileView.updateRecord(currentUser); or store.add(currentUser);. I checked the store and currentUser, they seems to be correct. What could be wrong? (My store's autoSync is set to true, so I think I don't need to call store.sync() after the store.add())

    Thanks

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,604
    Vote Rating
    818
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    If the store.add is failing then autoSync wouldn't work so there would be no request. It's kind of hard to debug something for someone when they don't step through to figure out what line is failing.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

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

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    42
    Vote Rating
    0
    bagusflyer is on a distinguished road

      0  

    Default


    Here is the call stacks:

    crash.jpg

    Does it help? I totally got no clue.

    Thanks

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,604
    Vote Rating
    818
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    store.add looks like it's ok, it's the syncing that isn't working.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

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

  5. #5
    Sencha User
    Join Date
    Dec 2011
    Posts
    42
    Vote Rating
    0
    bagusflyer is on a distinguished road

      0  

    Default


    Yes. I believe so. When I turn off autoSync, the code will not fail until I add store.sync at the end. So the problem must be related to sync. I'll debug more. Thanks

  6. #6
    Sencha User
    Join Date
    Dec 2011
    Posts
    42
    Vote Rating
    0
    bagusflyer is on a distinguished road

      0  

    Default


    I change the autoSync to false and manually run store.sync(). Yes, it failed in store.sync().

    Here is the code inside sync() function in sencha-touch-all.js:

    Code:
    sync: function() {
            if (typeof this.proxy.sync != 'function') {
                this.callParent(arguments);
            }else{
                this.proxy.sync(this);
            }
        },

    if (typeofthis.proxy.sync != 'function') return true, so this.proxy.sync(this); is never been called. I don't know whether that's the problem.

    Here is my source code for the store:

    Code:
    Ext.define('App.store.MyProfile', {
        extend : 'Ext.data.Store',
    
    
        model    : 'App.model.User',
        autoLoad : true,
        //autoSync : true,
    
        proxy: {
            type: 'localstorage',
            id: 'my-profile-store'
        }    
    });
    Somebody mentioned the localstorage in Sencha Touch 2.0 is broken. Is this true? If this is the cause, can I use JSON and save my data back to JSON file in server?

    Thanks

  7. #7
    Sencha User
    Join Date
    Dec 2011
    Posts
    42
    Vote Rating
    0
    bagusflyer is on a distinguished road

      0  

    Default


    Found a workaround:http://www.sencha.com/forum/showthre...t=Localstorage

    Thanks , I'll try that.

Thread Participants: 1