简体   繁体   English

ExtJS4 Model.save()错误:记录未定义。

[英]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. 我正在使用MVC架构使用ExtJS 4开发应用程序。 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: 无论是否使用回调,即使save()函数参数为空,也会出现以下错误:

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

Thrown in .../ext-4.0.1/src/data/Model.js on line 972. 在第972行的... / ext-4.0.1 / src / data / Model.js中抛出。

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. 在第968行(与上述同一Model.js文件相同)返回一个具有记录的对象,其中包含我正在传递的数据。

Two questions here: 这里有两个问题:

  1. Is this a bug? 这是错误吗?
  2. Am I doing something wrong? 难道我做错了什么?

Any help would be greatly appreciated. 任何帮助将不胜感激。

First I'd suggest that you upgrade to the latest version 4.0.2a , so you got the latest bug fixes. 首先,我建议您升级到最新版本4.0.2a ,以便获得最新的错误修复。

Ext JS has its own class system, so you cannot instantiate an Ext based class with new keyword. Ext JS具有自己的类系统,因此您无法使用new关键字实例化基于Ext的类。 Always use Ext.create to instantiate a new class from Ext JS and only use new for plain prototype based classes. 始终使用Ext.create从Ext JS实例化一个新类,并且仅将new用于基于普通原型的类。

For models you can create a new instance through the model manager: 对于模型,您可以通过模型管理器创建新实例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM