1

我有以下保存:

 var saveResponse = rene.save({
            success: function(response, opts) {
                console.log('The Child was saved, response: '+response);
            },
            failure: function(response, opts) {
                console.log('The Child save was a failure response: '+response);
                console.log('The Child save was a failure opts: '+opts);
            }
        });

服务器验证发送的数据,如果出现任何错误,它会返回:

{"validationErrors":{
    "phoneNumber":"Account with this email already exists",
    "birthDateString":"Use following format: yyyy-MM-dd. Example: 2012-11-22"}
}

但是 save 方法有以下 API,它只返回:

http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Model-method-save

"...它们都将被调用,模型和操作作为参数。",

所以我的问题是:

当它只为我提供模型时,如何获得响应(上面的 JSON)作为回报(我假设它只给我我在帖子正文中发送的原始 json,因为我不返回完整的模型作为回报)?是我忽略了什么,还是从语义的角度来看 REST POST 请求不应该失败(这里:验证错误)?

4

1 回答 1

1

我想通了,您将异常侦听器注册到代理,如下所示:

var account = Ext.create('Sencha.model.user.Adult', {
....
}

var proxy = account.getProxy();
proxy.addListener({
    'exception': function(proxy, response, operation) {
        var obj = JSON.parse(response.responseText);
            adultClass.serverValidationErrors(obj);
        }
});
于 2012-08-23T20:59:54.013 回答