Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

extjs - Store do something after sync with autoSync enabled

I'm trying to detect and remove those fields that after a sync are still on the store but are not added to the database (success: false). Then, return an error message to the user (with some error codes). However I can only see a "beforesync" event in store documentation.

Are there any possibility to do such a thing? I'm trying with "update" events but they are called after syncing only if the sync is successfull (otherwise they are called only before sync).

I can't really find an event that is fired after sync. Any solution for this?

Notice that I'm using autoSync, that's why I can't hook to the callback, otherwise everything will be easier.

Another important point I can see in the documentation is:

Code:

Ext.data.Model.EDIT
Ext.data.Model.REJECT
Ext.data.Model.COMMIT

Why REJECT event is never fired? I thought that if success = false REJECT would be called, do I require something like a 404 to obtain that result?

EDIT: No, I can't find a way to fire REJECT version of the update event. Any suggestion?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is, if you ask me, some design flaw in ExtJS.

AbstractStore has onCreateRecords, onUpdateRecords, and onDestroyRecords, which are empty functions you can override. You can call rejectChanges() if success is false there.

Ext.define('BS.store.Users', {
    extend: 'Ext.data.Store',    
    model: 'BS.model.User',

    autoSync: true,
    autoLoad: true,

    proxy: {
        type: 'direct',
        api: {
            create: Users.Create,
            read: Users.Get,
            update: Users.Update,
            destroy: Users.Delete,

        },
        reader: {
            type: 'json',
            root: 'data',
        },
    },

    onCreateRecords: function(records, operation, success) {
        console.log(records);
    },

    onUpdateRecords: function(records, operation, success) {
        console.log(records);
    },

    onDestroyRecords: function(records, operation, success) {
        console.log(records);
    },

});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...