-->

如何响应状态的基础上执行操作,而在Ext.js做同步(How to perform action o

2019-11-05 05:10发布

这是我的商店MyStore.js

Ext.define('myProject.store.MyStore', {
    config:{
        storeId:    'MyStore',
        autoLoad:   false,
        autoSync:   false,
        allowSingle: true,
        clearOnPageLoad:    true,

        model:              'abc.model.MyStoreModel',
        proxy: {
            type:   'rest',
            actionMethods: {create: 'POST', read: 'GET', update: 'POST', destroy: 'POST'},
              url:'/services/rest/MyService/myService',
            reader: {
                type: 'json',
                rootProperty:MyServiceView.elements.collection',
                successProperty : 'success'
            },
            writer:
            {
                type: 'json',
                root: 'MyServiceDataView',
                nameProperty: 'mapping',
                expandData : true
            },
            listeners: {
                exception:          function(proxy,response,operation){

                }
            }   
        }
    }
});

这是我的模型

Ext.define( 'myProject.model.MyStoreModel', {
    extend:         'Ext.data.Model',
    config:{
        idProperty:     'keyStr',
        fields:[
                {
                    name:           'keyStr',
                    type:           'string',
                },
                {
                    name:           'sId',
                    type:           'int'
                },
                {
                    name:           'dCode',
                    type:           'string'
                },
                {
                    name:           'sNumber',
                    type:           'int'
                }

            ]
    },

});

在我的Controller.js,我有这样的方法

syncMyStore: function()
    {

        var deferred = Q.defer();
        var successfulSync= 'false';
        var me = this;
        var myStore = Ext.getStore('MyStore');

        if(this.isSyncRequires(myStore)) //assume this is always true
        {
            myStore.sync({
                success: function () {
                    successfulSync = 'true';
                    deferred.fulfill();
                }
            });
        }
        else
        {
            deferred.fulfill();
        }
        return successfulSync;
    },
  1. 假设我有5个记录在我的商店即record0,RECORD2 ... RECORD4。
  2. 对于每一个记录,它在调用REST服务。 所以总的5 REST调用

要求1:除了使用成功财产,我想执行的状态代码的基础上,一些行动。 也就是说,如果状态代码是200,然后再考虑它的成功。

要求2:每次休息电话后,我想删除记录/标记脏的针对特定记录响应状态(200)的基础上假的。

手段,假设为RECORD1和RECORD2如果状态代码是200,然后我想删除/标记脏=虚假备案1,只有RECORD2。

我会为你真的很感谢你帮我出这一点。

Answer 1:

假设record0,RECORD1,RECORD3 ..有识别一些独特的方式。 做一个Ajax调用每个记录(REST API调用),那么如果响应是200,控制将达到“成功”的功能。 这时如果响应有数据来识别记录选择记录并更改其脏标志设置为false。 在故障功能做同样的改变脏标志设置为true。 有两件事情你需要遵循做出更好的答案

  1. 您将使用记录作为有效载荷为您的休息API调用?
  2. 将响应具有指示记录,即我得的GUID相关记录?


文章来源: How to perform action on the basis of response status while doing sync in Ext.js