Search code examples
javascriptmodel-view-controllermodelextjs4

ExtJS4 Model.save() error: record is undefined.


What I'm trying to do:

I'm making an app with ExtJS 4 using the MVC architecture. I have a Model (User) with the proxy, a store (Users), and a Controller.

The controller listens for a button to "Add User", which receives data from a form. I create a new User and pass in the data:

var newUser = new MY.model.User({name: textInputValue}); //bob

and then call

newUser.save({
    success: function() { ... },
    failure: function() { ... }
});

What is happening:

Whether I use the callbacks or not, and even if the save() function params are empty, I get the following error:

record is undefined:
me.set(record.data);

Thrown in .../ext-4.0.1/src/data/Model.js on line 972.

What I've been able to find out so far:

Running stack traces shows that:

operation = Ext.create('Ext.data.Operation', options);

on line 968 (of the same Model.js file mentioned above) returns an object that has records, of which has the data that I'm passing it.

Two questions here:

  1. Is this a bug?
  2. Am I doing something wrong?

Any help would be greatly appreciated.


Solution

  • First I'd suggest that you upgrade to the latest version 4.0.2a, so you got the latest bug fixes.

    Ext JS has its own class system, so you cannot instantiate an Ext based class with new keyword. Always use Ext.create to instantiate a new class from Ext JS and only use new for plain prototype based classes.

    For models you can create a new instance through the model manager:

    var user = Ext.ModelManager.create({
        name : 'Bob'
    }, 'User');