Extjs 4,带有复选框和loadRecord的表单

Jak*_*zok 5 forms checkbox model extjs

在我的Extjs4应用程序中,我有一个网格和一个表单.

用户模型:

Ext.define('TestApplication.model.User', {
    extend: 'Ext.data.Model',
    fields: [
      { name: 'id', type: 'int', useNull: true },
      { name: 'email', type: 'string'},
      { name: 'name', type: 'string'},
      { name: 'surname', type: 'string'}
    ],
    hasMany: { model: 'Agency', name: 'agencies' },
});
Run Code Online (Sandbox Code Playgroud)

和原子能机构:

Ext.define('Magellano.model.Agency', {
  extend: 'Ext.data.Model',
  fields: [
    {name: 'id', type: 'int', useNull: true},
    {name: 'name', type: 'string'}
  ]
});
Run Code Online (Sandbox Code Playgroud)

然后在我的表单中我创建了复选框:

[...]
  initComponent: function() {
    var store = Ext.getStore('Agencies');
    var checkbox_values = {xtype: 'checkboxfield', name: 'agencies[]'};
    var checkboxes = []

    store.each(function(record){
      var checkbox = {xtype: 'checkboxfield', name: 'agency_ids',
                      boxLabel: record.get('name'), inputValue: record.get('id')};
      checkbox.checked = true;
      checkboxes.push(checkbox)
    });
    this.items = [{
      title: 'User',
      xtype: 'fieldset',
      flex: 1,
      margin: '0 5 0 0',
      items: [{
        { xtype: 'textfield', name: 'email', fieldLabel: 'Email' },
        { xtype: 'textfield', name: 'name', fieldLabel: 'Nome' },
    }, {
      title: 'Agencies',
      xtype: 'fieldset',
      flex: 1,
      items: checkboxes
    }];
[...]
Run Code Online (Sandbox Code Playgroud)

一切都适用于发送表单我收到所有数据,并可以将其保存到数据库中.

当用户单击网格时,记录将以标准形式加载到表单中:

form.loadRecord(record);
Run Code Online (Sandbox Code Playgroud)

问题是没有选中复选框.复选框元素是否有任何命名约定,以便Extjs可以检测要设置的内容?如何设置关系以便表单能够理解要检查的内容?或者我应该手工完成所有事情?

Ras*_*hmi 2

在您的表单中,您可以执行以下操作:

{
   xtype: 'checkboxfield',
   name: 'test',                                
   boxLabel: 'Test',
   inputValue: 'true',
   uncheckedValue: 'false'
}
Run Code Online (Sandbox Code Playgroud)