javascript - ExtJS 传递 store.sync() 上的所有字段

标签 javascript ajax extjs

在 ExtJS 6.5.0 中,我创建了一个 Store 和一个可编辑的网格面板:

Ext.define('StateStore',{
    extend: 'Ext.data.Store',
    alias: 'store.stateStore',
    storeId  : 'StateStore',
    fields: ['Id', 'Name', 'SortIndex'],
    autoLoad : true,

    proxy: {
        type : 'ajax',
        api  : {
            create  : undefined,
            read    : '/kanban/states/read/' + kanbanId,
            update  : '/kanban/states/update/' + kanbanId,
            destroy : undefined
        },
        writer : {
            type        : 'json',
            allowSingle : false
        }
    }
});


var StateList = Ext.create({
    xtype : 'gridpanel',
    selModel: 'cellmodel',
    title : 'Manage States',
    store : {
        type: 'stateStore'
    },
    plugins: {
        ptype: 'cellediting',
        clicksToEdit: 1
    },
    columns: [
        {
            text: 'ID',
            dataIndex: 'Id',
            flex: 1
        },{
            text: 'Name',
            dataIndex: 'Name',
            flex: 2, 
            editor: {
                field: {
                    type: 'textfield',
                    allowBlank: false
                }
            }
        },
        { 
            text: 'SortIndex',
            dataIndex: 'SortIndex',
            flex: 1,
        }
    ],
});

当用户完成编辑并单击“保存”时,将调用store.sync()函数,但它只会将修改的记录和字段传递到服务器。我使用 record.dirty=true 强制它传递所有记录,但未修改的字段仍然没有传递。

为什么我要传递所有记录和字段?因为我想删除现有记录并在每次更新时创建新记录。所以我不需要单独处理创建/更新/删除。只有几个条目,因此性能不是问题。

一种解决方案是使用Ext.Ajax()而不是sync(),我想知道是否有更好的解决方案?

最佳答案

使用 writeAllFields: true 配置您的编写器。

相关docs .

关于javascript - ExtJS 传递 store.sync() 上的所有字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45704438/

相关文章:

java - Extjs 无法读取属性错误

javascript - Javascript中两个日期初始化的差异

JavaScript 与 IE8 的不兼容问题

javascript 不适用于 ajax 加载的内容;不使用jquery

java - 使用ajax调用Struts 2 Action ,直接向响应写入字符串,不返回字符串

node.js - 如何更新 sencha cordova 版本

javascript - jQuery $.isNumeric 在控制台上抛出错误

javascript - 如何使用 jQuery 发出 Django Ajax 请求?

javascript - 通过 AJAX 发送变量后无法获取 $_POST 值

javascript - 动态绑定(bind)组合的只读属性的 Extjs 问题