Why is there no sync callback in Sencha Touch?

久未见 提交于 2019-12-07 04:06:52

问题


I'd like to be able to show a message to the user once a store sync has successful completion. However, there doesn't seem to be any way of using a callback or calling this synchronously. I'm a little surprised this isn't provided out of the box as it must be a common problem.

Is there any work-around for this?


回答1:


It took us ages to find a proper solution to this. Finally we added listener to the store's write event what seems to be working properly. As it is needed frequently it has been added to the store prototype as

Ext.data.Store.prototype.syncWithListener = function(onWriteComplete, syncMethod) {

    this.on('write', onWriteComplete, this, {single:true});

    var syncResult = syncMethod ? syncMethod.apply(this) : this.sync();

    if (syncResult.added.length === 0 &&
        syncResult.updated.length === 0 &&
        syncResult.removed.length === 0) {

        this.removeListener('write', onWriteComplete, this, {single:true});
        onWriteComplete(this);    
    }

    return syncResult;
};


来源:https://stackoverflow.com/questions/14014068/why-is-there-no-sync-callback-in-sencha-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!