Extjs mvc将记录添加到网格面板

时间:2013-02-13 10:13:07

标签: model-view-controller extjs row add gridpanel

首先我认为这是一个简单的问题,但无论如何我无法解决它。

我有一个extjs gridpanel,它的商店和模型。从控制器,我可以插入新记录到存储,当我使用firebug和调试时,我可以列出商店中的所有新记录(panel.store.data.items)但是在gridview中我无法使其可见。

你可以告诉我在哪里以及我缺少什么吗?为什么记录没有列在网格中?

这是我的模特

Ext.define('BOM.model.PaketModel', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'seriNo', type: 'string' },
        { name: 'tutar', type: 'string' },
    ]
});

这是商店

Ext.define('BOM.store.PaketStore', {
    extend: 'Ext.data.Store',
    model: 'BOM.model.PaketModel',
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            root: 'data',
        },
        writer: {
            type: 'json',
            root: 'data',
        },
    },

});

这是我添加新行的方法

addNew: function () {
        this.getPaketWindow().returnRowEdit().cancelEdit();
        this.getPaketWindow().getStore().insert(0, new BOM.model.PaketModel());
        this.getPaketWindow().returnRowEdit().startEdit(0, 0);
    }

更新视图

Ext.define('BOM.view.PaketCreate', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.paketcreate',
    bodyPadding: 5,
    layout: 'fit',

    header:false,

    initComponent: function () {

        this.columns = [
            {   text: 'Seri No',        flex: 2,    sortable: true,     dataIndex: 'seriNo',        field: {xtype: 'textfield'} }, 
            {   text: 'Tutar',          flex: 2,    sortable: true,     dataIndex: 'tutar',         field: {xtype: 'textfield'} }
        ];
        this.dockedItems = [{
            xtype: 'toolbar',
            items: [{
                text: 'Ekle',
                id:'addNewCheck',
                iconCls: 'icon-add',

            },'-',{
                id: 'deleteCheck',
                text: 'Sil',
                iconCls: 'icon-delete',
                disabled: true,
           }]
        }];
        this.store = 'BOM.store.PaketStore';
        rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
            clicksToMoveEditor: 1,
            autoCancel: false
        });
        this.plugins = rowEditing,
        this.callParent(arguments);
    },
    returnRowEdit: function () {
        console.log("row editing...");
        return rowEditing;
    }
});
var rowEditing;

2 个答案:

答案 0 :(得分:1)

尝试:

this.store =  Ext.create('BOM.store.PaketStore');

而不是:

this.store = 'BOM.store.PaketStore';

http://jsfiddle.net/qzMb7/1/

答案 1 :(得分:0)

当我添加“.getView()”之类的

时,它会起作用
  

this.getPaketWindow()。getView()。getStore()。insert(0,new BOM.model.PaketModel())

但是,我还是不明白。当我手动添加记录时,两者都到达同一个商店我可以在store.data中看到它们但只有在我包含.getView()部分

时它才可见