在我的 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/