【问题标题】:Extjs 4, forms with checkboxes and loadRecordExtjs 4,带有复选框和 loadRecord 的表单
【发布时间】:2013-01-06 03:30:27
【问题描述】:

在我的 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' },
});

和机构:

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

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

[...]
  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
    }];
[...]

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

当用户点击网格时,记录会以标准格式加载:

form.loadRecord(record);

问题是未选中复选框。复选框元素是否有任何命名约定,以便 Extjs 可以检测到要设置的内容?如何设置关系以便表单了解要检查的内容?还是我应该手工做所有事情?

【问题讨论】:

    标签: forms extjs model checkbox


    【解决方案1】:

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

    {
       xtype: 'checkboxfield',
       name: 'test',                                
       boxLabel: 'Test',
       inputValue: 'true',
       uncheckedValue: 'false'
    }
    

    【讨论】:

    • 我将此参数添加到复选框,但没有任何改变...表单上的复选框到底有什么问题?
    • 我的问题是我在使用 xtype: 'textfield' 和 inputType: 'checkbox' 时出现了功能,但在我更改 xtype 之前无法正常工作。谢谢
    【解决方案2】:

    我相信您必须使用someCheckbox.setValue(true) 动态检查复选框,或取消选中someCheckbox.setValue(false)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2011-12-30
      • 2018-05-12
      • 2016-01-22
      • 2014-01-19
      相关资源
      最近更新 更多