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



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

策略是首先在postCreate期间一次性定义Tooltip,然后将其传递给处理程序函数,处理程序函数会将其动态添加到节点中。

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动态分配给鼠标悬停元素的正确方法是什么?

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

您可以对工具提示执行类似操作。请记住,您需要在小部件定义中要求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);
     }
  });
}

最新更新