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

标签 forms extjs model checkbox

在我的 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 可以检测要设置的内容?如何设置关系以便表单了解要检查的内容?还是我应该手工做所有事情?

最佳答案

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

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

关于forms - Extjs 4,带有复选框和 loadRecord 的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7474101/

相关文章:

jquery - 我如何使用 jQuery 在我的网站演示中自动填写表单,就像真人在实际输入一样?

javascript - extjs4 对象不支持属性或方法 'indexOf' IE 8 解决方法问题

xml - 通过源模型函数从源模型中删除行时 QSortFilterProxyModel 崩溃

javascript - Extjs:仅当另一个字段有值时才显示复选框

javascript - sails.js:刷新之前,新创建的记录不会填充在页面上

collections - 为什么在 Backbone Collection 中指定模型

asp.net - 为什么 "renderAllHiddenFieldsAtTopOfForm"不工作?

javascript - 如何在焦点上显示/隐藏输入值?

javascript - 在表单中显示html数据

javascript - 禁用 sencha 数据 View 列表上的滚动