我已经设置了一个复选框和一个组合框,并且我正在尝试设置一个功能 - 当用户选中该复选框时,组合框必须出现。我是 extjs 新手,在设置此功能的函数时遇到问题。
Ext.onReady(function() {
var tests = [
['Test1'],
['Test3'],
['Test2']
];
Ext.define('Testfile.model.Test', {
extend: 'Ext.data.Model',
fields: ['test']
});
var testsStore = new Ext.data.Store({
model: 'Testfile.model.Test',
proxy: {
type: 'memory',
reader: {
type: 'array'
}
},
data: tests
});
var form = Ext.create('Ext.form.Panel', {
renderTo: document.body,
bodyPadding: 10,
width: 550,
style: 'margin:16px',
height: 300,
title: 'Testing example',
items: [{
xtype: 'checkbox',
name: 'system',
boxLabel: 'Production (PACTV)',
iputValue: 'production',
listeners: {
check: function (checkbox, isChecked) {
var sample = Ext.getCmp('secondComboID');
}
}
}, {
xtype: 'combobox'
fieldLabel: 'Select Test',
id: 'secondComboID',
store: testsStore,
valueField: 'id',
displayField: 'test',
typeAhead: true,
forceSelection: true,
allowBlank: false,
editable: true,
triggerAction: 'all',
lastQuery: ''
}]
});
Ext.getBody().add(me.form);
})
有人可以建议修复脚本吗?
最佳答案
我将使用change
事件:http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.field.Checkbox-event-change
listeners: {
change: function(checkbox, newValue, oldValue, eOpts) {
var combo = checkbox.up('form').down('combobox');
if (newValue) {
combo.show();
} else {
combo.hide();
}
}
}
此外,请注意层次导航方法 up()
和 down()
的使用。使用这些(或其他相关方法)来查找组件比使用硬编码组件 ID 更可取。
这是您的代码的工作示例: https://fiddle.sencha.com/#fiddle/ua
关于extjs - 选中复选框时显示组合框 - Extjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19323863/