【问题标题】:ExtJs Ext.grid.Panel access model from columnExtJs Ext.grid.Panel 从列访问模型
【发布时间】:2014-02-18 00:35:50
【问题描述】:

在 Ext.grid.Panel 中,当用户更改复选框的状态时,我需要保存代表该行的模型。

我有这段代码(很简单,因为这个组件很大):

Ext.define('Hts.Appointments.List.Grid', {
    extend        : 'Ext.grid.Panel',
    initComponent : function() {
        this.store = /* Big initialization code for store */
        this.columns = [{
            header: Hts.Localization.APPOINTMENTS.HIGHLIGHT,
            dataIndex: 'highlighted',
            xtype: 'checkcolumn',
            flex: 1,
            listeners: {
                checkchange: function(column,rowIndex,checked) {
                       /* Here I need to access the model and save it */
                }
            },
            /* other columns */
        ]
    }
})

我希望我提供了足够的信息(我是 ExtJs 的新手)。

【问题讨论】:

    标签: javascript extjs


    【解决方案1】:

    使用属性 'idProperty' 使用 id 定义您的模型。

    Ext.define('Model', {
        extend: 'Ext.data.Model',
        idProperty: 'idProp',
        fields: [
            { name: 'id', type: 'int' },
            { name: 'name', type: 'string' }
        ]
    });
    

    你可以得到模型并保存它:

    listeners: {
                    checkchange: function(column,rowIndex,checked) {
                           var model = Ext.ModelManager.getModel('idProp'); // access
                           model.save(); //save
                    }
                },
    

    【讨论】:

    • 不幸的是我使用版本 3.* 并且没有这样的属性“idProp”。而且我只需要保存一行(复选框在哪里),而不是表中的所有数据。
    • 啊对不起,我的错 :) 我只使用 4.*,所以我不知道 3.*...我希望有人能尽快帮助你!祝你好运
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多