extjs 解决使用store.sync()方法更新item有时不触发后台action的问题

问题描述:

extjs 解决使用store.sync()方法更新item有时不触发后台action,不出发后台action的原因是item的字段值没有变化

解决方法:

item.setDirty(true)

 

追查问题步骤

1、store.sync()方法               

            this_.win.store.sync({
                timeout: 1000000,
                success: function() {
                    Ext.Msg.alert('系统提示', '修改数据成功!');
                    // this_.win.gridPanel.refresh();
                    this_.win.close();
                    // me.treeRefresh(name);
 this_.win.store.load(); }, failure: function() { Ext.Msg.alert("系统提示", failMessage); this_.win.close(); this_.win.store.load(); } });

2、sync方法源码

sync: function(options) {
        var me = this,
            operations = {},
            toCreate = me.getNewRecords(),
            toUpdate = me.getUpdatedRecords(),
            toDestroy = me.getRemovedRecords(), needsSync = false; if (toCreate.length > 0) { operations.create = toCreate; needsSync = true; } if (toUpdate.length > 0) { operations.update = toUpdate; needsSync = true; }
getUpdatedRecords: function() {
        return this.data.filterBy(this.filterUpdated).items;
    },
filterBy : function(fn, scope) {
        var me = this,
            newMC  = new me.self(me.initialConfig),
            keys   = me.keys,
            items  = me.items,
            length = items.length, i; newMC.getKey = me.getKey; for (i = 0; i < length; i++) { if (fn.call(scope || me, items[i], keys[i])) { newMC.add(keys[i], items[i]); } } return newMC; },
filterUpdated: function(item) {
        
        return item.dirty === true && item.phantom !== true && item.isValid();
    },

3、追查到items的类型是Ext.data.Store, item的类型是Ext.data.Model,Model有setDirty和dirty方法,在触发sync方法之前,item.setDirty(true)即可

转载于:https://www.cnblogs.com/Kevin00/p/8295519.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值