简体   繁体   English

如何在运行时更改ExtJS ToolTip文本?

[英]How to change ExtJS ToolTip text in runtime?

According to number of questions and articles the simple tip.html = 'new value'; 根据问题和文章的数量,简单的tip.html = 'new value'; should work but for some reasons it's not the case for me. 应该工作,但由于某些原因,我不是这样。

Here I have created a demo to demonstrate that tip.html modification doesn't change tip's body after it was rendered once: 在这里,我创建了一个演示来演示tip.html修改在渲染一次后不会改变tip的主体:

http://jsfiddle.net/zcYqe/1/ http://jsfiddle.net/zcYqe/1/

Steps to reproduce: 重现步骤:

Scenario 1: 场景1:

  1. Move mouse over red square to see the tip 将鼠标移到红色方块上以查看提示
  2. Press button 按下按钮
  3. See the tip isn't changed 看到提示没有改变

Scenario 2: 场景2:

  1. Press button (not - don't put mouse over red square) 按下按钮(不是 - 不要将鼠标放在红色方块上)
  2. See the tip's value has changed 看到提示的值已经改变

What am I missing? 我错过了什么? How would one change it in runtime (Scenario 1)? 如何在运行时更改它(场景1)?

您不能只设置属性,一旦创建了组件,您需要调用一个方法,以便它实际更新底层DOM:

tip.update('new');

You can accomplish this with a beforeshow listener in ExtJS 4.2.x (and probably earlier). 您可以使用ExtJS 4.2.x中的beforeshow侦听器(可能更早)完成此操作。

var changeCount = 1;

var tip = Ext.create('Ext.tip.ToolTip', {
    target: 'hoverme',
    html: 'Press this button to clear the form',
    listeners: {
        // Change content dynamically depending on which element triggered the show.
        beforeshow: function updateTipBody(tip) {
            tip.update( "Changed " + changeCount + " times" );
            changeCount ++;
        }
    }

});

document.getElementById('btn').addEventListener('click', function(e) {
    tip.html = 'new';
    return false;
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM