2014-02-17 34 views
0

在Ext.grid.Panel中当用户更改复选框的状态时,我需要保存表示此行的模型。ExtJs 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的)。

回答

0

使用属性'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 
       } 
      }, 
+0

Unfortuanally我使用的版本为3 *并没有这样的属性“idProp”。而且我只需要保存一行(复选框在哪里),而不是表中的所有数据。 –

+0

啊对不起,我的不好:)我只和4.一起工作*所以我不知道3。* ...我希望有人能尽快帮助你!祝你好运 – Paparis