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)即可

  • 相关阅读:
    ini_set /ini_get函数功能-----PHP
    【转】那个什么都懂的家伙
    word 2007为不同页插入不同页眉页脚
    August 26th 2017 Week 34th Saturday
    【2017-11-08】Linux与openCV:opencv版本查看及库文件位置等
    August 25th 2017 Week 34th Friday
    August 24th 2017 Week 34th Thursday
    August 23rd 2017 Week 34th Wednesday
    August 22nd 2017 Week 34th Tuesday
    August 21st 2017 Week 34th Monday
  • 原文地址:https://www.cnblogs.com/Kevin00/p/8295519.html
Copyright © 2011-2022 走看看