1

我想知道为什么我不能执行以下操作:

newChallenge = Ext.create('App.model.User', {name:'donald'});
newChallenge.save();
*** After another user action ***
newChallenge.set('name','george');
newChallenge.save();

我遇到的问题是第二次保存/更新甚至没有在第一次保存/更新之后触发 AJAX 补丁/发布到服务器并且没有将名称设置为“乔治”

我在日志中看不到任何错误,也看不到数据库中的更新。

模型:

Ext.define('App.model.User', {
    extend: 'Ext.data.Model',
    requires: [
        'Ext.data.identifier.Uuid'
    ],
    config: {
        identifier: 'uuid',
        fields: [
            { name: 'id', type: 'auto', persist: false },
            { name: 'name', type: 'string' }

        ]           
        proxy: {
            type: 'rest',
            api: {
                create: App.util.Config.getApiUrl('user_profile'),
                update: App.util.Config.getApiUrl('user_profile'),
                read: App.util.Config.getApiUrl('user_profile')
            },
            reader: {
                type: 'json'
            },
            writer: { 
                type: 'json-custom-writer-extended',
                writeAllFields: true,
                nameProperty: 'mapping'
            }
        }
    }
});

服务器响应(TastyPie):

{
   "name":"george",
   "id":35,
   "resource_uri":"/app/api/1/user/35/",
   "start_date":"2013-08-06T14:49:11.030298"
}

谢谢,史蒂夫

4

1 回答 1

0

你忘了说明什么问题,不是吗?你知道,我期望什么,我得到什么...

无论如何,您的代码已损坏,因为它依赖于save()同步调用(这意味着第一次调用将阻塞,直到收到并处理响应),而事实并非如此。你应该从解决这个问题开始:

newChallenge = Ext.create('App.model.User', {name:'donald'});
newChallenge.save({
    success: function(model) {
        newChallenge.set('name','george');
        newChallenge.save(); // you should handle error here too
    }
    // you should handle error cases too...
});
于 2013-08-07T14:20:04.087 回答