Results 1 to 7 of 7

Thread: Can't save into store

  1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    42
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

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

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    42
    Vote Rating
    0
      0  

    Default

    Here is the call stacks:

    crash.jpg

    Does it help? I totally got no clue.

    Thanks

  4. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Vote Rating
    1272
      0  

    Default

    store.add looks like it's ok, it's the syncing that isn't working.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

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

  5. #5
    Sencha User
    Join Date
    Dec 2011
    Posts
    42
    Vote Rating
    0
      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
      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
      0  

    Default

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

    Thanks , I'll try that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •