【问题标题】:How to getValues from grid and POST them. EXTJS如何从网格中获取值并发布它们。 EXTJS
【发布时间】:2019-01-16 08:44:14
【问题描述】:

我对网格中的 getValues 感兴趣并发布它们,使用网格的自定义编辑表单上的按钮 confirm

但我不知道如何getValues()。我不能使用它,否则会导致值在“fieldset”xtype 内完成。

如何获取网格值...也许存在一些方法,允许将 grideditable 插件配置设置为 Ajax 请求配置参数?

我的部分代码:

Ext.define('Foresto.model.EditListRenters', {
            extend: 'Ext.grid.Grid',
            xtype: 'rentlist',
            requires: [
                'Ext.grid.plugin.Editable',
                'Foresto.model.RentsListModel'
            ],
            store: {
                model: 'Foresto.model.RentsListModel',
                autoLoad: true,
                pageSize: 0,
                proxy: {
                    type: 'ajax',
                    url: '/myownurl',
                    reader: {
                        type: 'json',
                        rootProperty: 'results'
                    }

                }
            },
            plugins: [{
                type: 'grideditable',
                triggerEvent: 'doubletap',
                enableDeleteButton: true,
                formConfig: null,

                defaultFormConfig: {
                    xtype: 'formpanel',
                    title: 'Редактировать договор',
                    scrollable: true,
                    items: {
                        xtype: 'fieldset'
                    }
                },

                toolbarConfig: {
                    xtype: 'titlebar',
                    cls: 'hdr2',
                    height: 46.63,
                    docked: 'top',
                    items: [{
                        xtype: 'button',
                        ui: 'decline',
                        cls: 'grbuttons',
                        text: 'cancel',
                        align: 'left',
                        action: 'cancel'
                    }, {
                        xtype: 'button',
                        ui: 'confirm',
                        cls: 'grbuttons',
                        text: 'submit',
                        align: 'right',
                        action: 'submit',
                        handler: function() {

                            var rentset = _.getValues() //how get values??



                            Ext.Ajax.request({
                                url: '/myownurl/contract/',
                                method: 'POST',
                                params: rentset
                            })
                        }
                    }]
                }

            }],
            columns: [ //my columns]
  });

【问题讨论】:

    标签: javascript extjs extjs4 extjs6 extjs6-modern


    【解决方案1】:

    Extjs 使用 MVC 模式,因此您不需要手动挖掘更改的值。您的数据记录(干净的和脏的)在存储中,连接由代理管理。 Grid只是一个可视化数据的可视化组件,它的插件是改变数据的助手。

    不要(重新)在您的函数中创建新请求,而是告诉商店完成这项工作:

    handler: function () {
        form.updateRecord();
        form.hide();
        grid.getStore().sync();
    }
    

    另外,指定代理参数:

    proxy: {
        type: 'ajax',
        batchActions: true,
        url: './myownurl',
        actionMethods: {
            create: 'POST',
            read: 'POST',
            update: 'POST',
            destroy: 'POST'
        },
        reader: {
            type: 'json',
            rootProperty: 'results'
        },
        writer: {
            type: 'json',
            root: 'data',
            encode: true,
            writeAllFields: true,
        }
    }
    

    【讨论】:

      【解决方案2】:

      使用

      获取修改后的记录
      grid.getStore().getModifiedRecords();
      

      获取自上次提交以来添加或更新的所有记录。

      【讨论】:

        猜你喜欢
        • 2014-02-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-02
        • 2013-08-29
        • 2012-01-21
        • 2013-01-21
        • 2013-04-18
        相关资源
        最近更新 更多