extjs REST api 保存数据

发布于 2024-11-09 11:55:14 字数 1413 浏览 0 评论 0原文

我正在使用休息服务(POST)将用户保存到服务器的数据库中。用户被发送并保存在我的数据库中,但响应未正确解释并且执行停止。一遍又一遍地寻找解决我的问题的方法,但似乎找不到任何解决方案。

这是我的控制器代码:

addUser: function () {
    var form = this.addUserWindow.down('form').getForm ();
    if (form.isValid()) {
        var user = new AP.model.User(form.getValues ());
        if ( user.validate () ) {
            user.save ({
                success: function() {
                    this.addUserWindow.destroy();//     destroys this window
                    this._reloadStore ();//     reloads a grid
                }
            });
        }
    }
}

在 user.save 方法上,即使发布数据并保存记录并返回,执行也会停止,如下所示:

{"data":{"username":"xyz","email":"[email protected]","password":"abcd","id":"1"},"success":true,"error":null,"errors":[]}

错误说:

Uncaught TypeError: Cannot read property 'data' of undefined
callback                            ext-all-debug.js:26824
Ext.define.processResponse                  ext-all-debug.js:26044
(anonymous function)                        ext-all-debug.js:26240
Ext.apply.callback                          ext-all-debug.js:5140
Ext.define.onComplete                       ext-all-debug.js:20950
Ext.define.onStateChange                    ext-all-debug.js:20912
(anonymous function)

I'm saving a user to my server's database using rest services (POST). The user gets sent and saved allright in my db but the response is not interpreted right and the execution stops. Searched over and over again for a solution to my problem but can't seem to find any.

Here's my controller code:

addUser: function () {
    var form = this.addUserWindow.down('form').getForm ();
    if (form.isValid()) {
        var user = new AP.model.User(form.getValues ());
        if ( user.validate () ) {
            user.save ({
                success: function() {
                    this.addUserWindow.destroy();//     destroys this window
                    this._reloadStore ();//     reloads a grid
                }
            });
        }
    }
}

On user.save method the execution stops even though the data is posted and record saved and returned like this:

{"data":{"username":"xyz","email":"[email protected]","password":"abcd","id":"1"},"success":true,"error":null,"errors":[]}

The error says:

Uncaught TypeError: Cannot read property 'data' of undefined
callback                            ext-all-debug.js:26824
Ext.define.processResponse                  ext-all-debug.js:26044
(anonymous function)                        ext-all-debug.js:26240
Ext.apply.callback                          ext-all-debug.js:5140
Ext.define.onComplete                       ext-all-debug.js:20950
Ext.define.onStateChange                    ext-all-debug.js:20912
(anonymous function)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪梦之恋 2024-11-16 11:55:14

返回记录:

{"data":"username":"xyz","email":"[email protected]","password":"abcd","id":"1"},"success":true,"error":null,"errors":[]}

其中“data”应该是阅读器中定义的根属性。

The return record:

{"data":"username":"xyz","email":"[email protected]","password":"abcd","id":"1"},"success":true,"error":null,"errors":[]}

where "data" should be the root property defined in the reader.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文