extjs - 如何以编程方式将工具提示添加到组合框
问题描述
我正在尝试combobox
使用以下代码在运行时向 a 添加提示,但它不起作用:
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
推荐阅读
- java - 如何在输入空输入时跳出循环
- docker - Azure 启用内容信任会影响注册表中的现有图像吗?
- string - SQLite:更新数据库中的每个“空”字符串记录
- mysql - 如果它与连续行中的列值匹配,则 SQL 查询以获取周期数并给出周期的总时间
- vhdl - VHDL检查字符串是否为空
- c# - 如何搜索大于或等于来自同一 DataGridView 的值?
- vue.js - 如何清空 html 标签的内容?
- java - Java CountDownLatch 等待异步回调
- api - 通过 Bitbucket API 更新 Bitbucket 拉取请求的描述
- amazon-web-services - 从 VPC 访问 AWS 网络负载均衡器