如何以编程方式将工具提示添加到组合框



我正在尝试使用以下代码在运行时向combobox添加提示,但它不起作用:

onStartReport: function (aButton) {
var lTip = Ext.getCmp('datasources');
lTip.setTooltip("Information on datasource");
}

我也尝试过这个,但我得到一个错误:

onStartReport: function (aButton) {
var tip = Ext.create('Ext.tip.ToolTip', {
target: 'datasources',
html: 'Information on datasource'
});        
}

查看经典:

{
xtype: 'combo',
itemId: 'datasources',
name: 'datasources',
fieldLabel: 'Data sources',
displayField: 'description',
valueField: 'id',
queryMode: 'local',
value: 0,
forceSelection: true,
editable: false,   
store: {
data: [
{id: 0, description: 'OnLine'},
{id: 1, description: 'History'}
],
fields: [
{name: 'id', type: 'int'},
{name: 'description', type: 'string'}               
],
autoLoad: true
}
}

这个方法应该没问题:

onStartReport: function (aButton) {
var tip = Ext.create('Ext.tip.ToolTip', {
target: 'datasources',
html: 'Information on datasource'
});

问题是您的组件实际上没有id,您添加的唯一配置是itemId并且它们并不完全相同,请参阅文档。这也是Ext.getCmp('datasources')不起作用的原因。

解决此问题的一种方法是简单地将itemId更改为id,即可找到引用。

如果您不想向组件添加 id,并继续使用 itemId,则可以使用以下代码:

onStartReport: function (aButton) {
var combo = Ext.ComponentQuery.query('#datasources')[0],
tip = Ext.create('Ext.tip.ToolTip', {
target: combo.el,
html: 'Information on datasource'
});

还有第三个选项,即在与调用onStartReport方法的组件/控制器的关系中抓取组合框。 我在这里添加了一个例子:https://fiddle.sencha.com/#view/editor&fiddle/2hap

最新更新