javascript - 当新记录添加到他的商店时网格不更新

标签 javascript extjs extjs4.2

我有一个网格面板,当在其商店中插入记录时,该网格面板不会更新。

型号:

Ext.define('S1.model.Ciot', {
    extend: 'Ext.data.Model',
    requires: 'S1.proxy.Ciot',
    proxy: 'ciot',
    associations: [
        {
            type: 'belongsTo',
            model: 'S1.model.Person',
            associatedName: 'owner',
            primaryKey: 'id',
            foreignKey: 'owner_id',
            associationKey: 'owner',
            setterName: 'setOwner',
            getterName: 'getOwner'
        }
    ],
    fields: [
        {name: 'id', type: 'int', useNull: true},
        {name: "owner_id", type: 'int', useNull: true},
        {name: "number", type: 'int', useNull: true},
        {name: "status", type: 'int', useNull: true},
        {name: "product", type: 'string', useNull: true}
    ]
});

商店:

Ext.define('S1.store.Ciot', {
    autoLoad: true,
    extend: 'Ext.data.Store',
    requires: 'S1.proxy.Ciot',
    model: 'S1.model.Ciot',
    proxy: 'ciot',
    remoteSort: true,
    remoteFilter: true,
    remoteGroup: true,
    pageSize: 40
});

Controller :

Ext.define('S1.controller.Ciot', {
    extend: 'Ext.app.Controller',
    stores: [
        'Ciot'
    ],
    models: [
        'Ciot'
    ],
    views: [
        'ciot.Window',
        'ciot.Grid',
        'ciot.EditWindow',
        'ciot.Form'
    ],
    init: function () {
        var me = this;
        me.control({
            'ciotgrid button[name=new]': {
                click: me.onNewButtonClick
            },
            'ciotgrid': {
                itemdblclick: me.onGridItemDblClick
            },
            'ciotform button[name=save]': {
                click: me.onButtonSaveClick
            }
        });
    },
    onNewButtonClick: function (bt) {
        var record = Ext.create('S1.model.Ciot'),
            grid = bt.up('grid');
        this.openEditWindow(record, grid);
    },
    onGridItemDblClick: function (v, record) {
        this.openEditWindow(record, v);
    },
    openEditWindow: function (record, grid) {
        var w = Ext.create('S1.view.ciot.EditWindow');
        w.setGrid(grid || null);
        w.show();
        w.down('form').loadRecord(record);
    },
    onButtonSaveClick: function (bt) {
        var form = bt.up('form'),
            record = form.getRecord();
        if (!record) {
            return false;
        }
        if (!form.getForm().isValid()) {
            return false;
        }
        form.updateRecord();
        record.save({
            success: this.onSaveSuccess,
            failure: this.onSaveFailure,
            scope: form
        });
    },
    onSaveSuccess: function (r, op) {
        var w = this.up('cioteditwindow'),
            grid = w.getGrid(),
            rs = op.getResultSet();
        grid.getStore().insert(0, rs.records[0]);
        w.close();
    },
    onSaveFailure: function (record, op) {
        // ...
    }
});

回调 onSaveSuccess 成功将新记录添加到网格中,但前端没有任何反应。

后端返回的记录正常。

看起来我插入新记录的网格与渲染的网格不同。

我在这里做错了什么?

谢谢。

ps:为了演示目的,代码被缩短。

最佳答案

尝试刷新网格:

      onSaveSuccess: function (r, op) {
            var w = this.up('cioteditwindow'),
                grid = w.getGrid(),
                rs = op.getResultSet();
            grid.getStore().insert(0, rs.records[0]);
 -->         grid.getView().refresh();
            w.close();
        },

关于javascript - 当新记录添加到他的商店时网格不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33242728/

相关文章:

javascript - 此 .ejs 文件中的 else 语句显示错误 "Unexpected token else in/home/ubuntu/workspace/v1/views/home.ejs while compiling ejs"

javascript - 如何在 Three.js 中不拉伸(stretch)地重复纹理?

javascript - AJAX jquery json发送数组到php

javascript - Ext JS 过滤呈现的列

extjs - 在 ExtJS htmleditor 中隐藏工具栏后如何保持顶部边框

javascript - Ext JS - 仅限于手动单元格编辑。

javascript - 自动生成的 getter 未定义 - ExtJS 4

javascript - 无法在 php 中检索 $_POST 变量

Extjs 路由器传递多个参数

extjs - 那么sencha sdk到底在哪里?