【问题标题】:How to include the icon inside the tooltip message如何在工具提示消息中包含图标
【发布时间】:2018-07-23 06:48:07
【问题描述】:

我需要在工具提示消息中包含下载图标,我尝试了以下代码:

ObjectIconView: Ember.ContainerView.extend(childMOMixin, {
                iconDownload: function () {
                              model: 'download'
                },
                mouseEnter: function(e) {
                if(type == 'Text'){
                var textUrl = {content: 'Preview is Not Available, Use '+ this.iconDownload() +'Menu'};
                this.$().tooltip(textUrl);
}
}

我在工具提示中调用了iconDownload。但它在输出中说undefined。我正在使用 Ember 1.4.0 版本。任何人都可以为此提供建议。我是 Ember 的新手。提前致谢

【问题讨论】:

  • 第 2 行代码中存在语法错误。``function () { model: 'download' }` 不是有效的 JavaScript。如果您可以包含库提供的$().tooltip(),这也会很有帮助。

标签: javascript jquery ember.js


【解决方案1】:

为了让工具提示显示您期望的数据,您需要更改两件事。

1:从iconDownload返回一些东西
现在,该函数什么都不返回,它创建一个内部列表,然后什么也不做。
它甚至需要是一个函数,还是只是一个字符串、对象?

2:您没有正确访问其中的数据。
假设您实际上需要返回一个哈希值,那么您没有正确访问数据 - 您所做的只是获取对象。
使用您现在拥有的结构,您的字符串生成器将是 'Preview is Not Available, Use '+ this.iconDownload().model +'Menu'


如果可能的话,我建议进行一些额外的更改。

1:使用 Ember getter 从 iconDownload 获取数据。
代替this.iconDownload,调用this.get('iconDownload.model')this.get('iconDownload')

2:使实际的工具提示文本成为计算属性。

toolTipText: function () {
    return `Preview is Not Available, Use ${this.get('iconDownload.model')} Menu`;
}.property('iconDownload.model');

现在,您可以调用 this.get('toolTipText') 来获取工具提示的内容。

3:将 mouseEnter 函数移动到视图 javascript 的操作部分

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多