extjs REST api保存数据

时间:2011-05-26 01:35:07

标签: extjs

我正在使用休息服务(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":"z@x.com","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)

1 个答案:

答案 0 :(得分:1)

回程记录:

{"data":"username":"xyz","email":"z@x.com","password":"abcd","id":"1"},"success":true,"error":null,"errors":[]}

其中"data"应该是读者中定义的root属性。