store.sync超时弹出失败的消息

时间:2013-12-13 11:34:12

标签: extjs

var BtnRouteSeqSave = Ext.getCmp('BtnRouteSeqSave');
var grid = Ext.getCmp('MyGridPanelRouteSeq');
grid.setLoading(true);
BtnRouteSeqSave.on('click', function(){

        RouteSeqStore.sync({

                success: function(batch) {
                            //var button = Ext.getCmp('BtnRouteSeqRefresh');
                            //button.fireEvent('click', button); //need at here , if not too fast refresh will get the old data
                            grid.setLoading(false);
                            Ext.MessageBox.show({
                                title: "Information",
                                msg: batch.operations[0].request.scope.reader.jsonData["message"],
                                icon: Ext.MessageBox.INFO,
                                buttons: Ext.MessageBox.OK,
                                fn: function(buttonId) {
                                    if (buttonId === "ok") {
                                        //EditWin.close();
                                    }
                                }
                            });  
                },
                    failure: function(batch){
                        //var button = Ext.getCmp('BtnRouteSeqRefresh');
                        //button.fireEvent('click', button); //need at here , if not too fast refresh will get the old data
                        grid.setLoading(false);
                        RouteSeqStore.rejectChanges();
                                   Ext.MessageBox.show({
                                title: "Error",
                                msg: batch.operations[0].request.scope.reader.jsonData["message"],
                                icon: Ext.MessageBox.ERROR,
                                buttons: Ext.MessageBox.OK,
                                fn: function(buttonId) {
                                    if (buttonId === "ok") {
                                        //EditWin.close();
                                    }
                                }
                    });  

                }

            });         
})  

这是datastore.sync成功与失败,
但是当我想要grid.setLoading(false);时超时 如何在这里实现这个功能?让我们说30秒后会自动超时并弹出消息Update Failed !并隐藏grid.setLoading(false);

的加载

1 个答案:

答案 0 :(得分:0)

你必须听服务器提供的异常(在你的RouteSeqStore中) 看看文档: Ext.data.proxy.Ajax-event-exception

Ext.define('xxx.store.xxx', {
    extend: 'Ext.data.Store',
    autoLoad: false,
    requires: [
        'xxx.model.xxx'
    ],
    model: 'xxx.model.xxx',
    proxy: {
        type: 'ajax',
        limitParam: null,
        timeout: 60000,
        url: 'bin/script.php',
        reader: {
            type: 'json',
            root: 'data',
            idProperty: 'xid'
        },
        // maybe this is what you need
        listeners: {
            exception: function (this, response, operation, eOpts) {
                // TIMEOUT DO SOMTHING
            }
        }
    }
});