动态地将单个Dojo工具提示分配给多个节点

时间:2015-04-18 07:21:55

标签: javascript dojo tooltip

想象一下,我们有一个包含节点列表的小部件(例如div)。我们想在鼠标悬停时显示Dojo Tooltip。里面的元素是动态生成的,因此我们必须以编程方式添加工具提示。

策略是首先在Tooltip期间定义postCreate单个时间,然后将其传递给handler-function,它将动态地将其添加到节点。

postCreate: function() {
  var _this = this;
  var fooTooltip = new Tooltip();

  this.own(on(this, '.elements-container-item', function(e) {
    lang.hitch(_this, 'onMouseOverHandler')(this, e, fooTooltip);
  });
}

Tooltip动态分配给mouseover' ed元素的正确方法是什么?

onMouseOverHandler: function(node, e, fooTooltip) {
  fooTooltip.set('connectId', [node]); // doesn't work
  fooTooltip.set('label', 'foo label'); // doesn't work as well
}

1 个答案:

答案 0 :(得分:1)

您可以为工具提示执行类似的操作。 请记住,您需要在窗口小部件定义中要求dojo/query

postCreate: function() {
  var _this = this;
  var containerNode = this.domNode; // Assuming that the widget has a domNode

  var fooTooltip = new Tooltip({
     connectId: query('.list-container', containerNode ), // Search the Node starting at the containerNode.
     selector: '.list-container-item',
     getContent: function(matchedNode) {
        console.debug('this is a tooltip for ', matchedNode);
     }
  });

}
相关问题