1

なぜ次のことができないのか疑問に思っています。

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

私が抱えている問題は、2 回目の保存/更新で、最初の保存/更新後にサーバーへの AJAX パッチ/投稿がトリガーされず、名前が「george」に設定されていないことです。

ログにエラーが表示されたり、DB が更新されたりすることはありません。

モデル:

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 に答える