zoukankan      html  css  js  c++  java
  • 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)即可

  • 相关阅读:
    jvm client模式和server模式
    TOMCAT开启APR模式
    Spring MVC 关于controller的字符编码问题
    彻底解决Spring MVC 中文乱码 问题
    js中字符串拼接html
    分布式文件系统之MooseFS----介绍
    CopyFile函數詳解
    Delphi 接口使用中,对象生命周期管理,如何释放需要注意的问题
    年度调查 看看 2016 年 Go 语言调查结果
    Sleep(0)的作用
  • 原文地址:https://www.cnblogs.com/Kevin00/p/8295519.html
Copyright © 2011-2022 走看看