使用 'selector' 属性将 Dojo 工具提示分配给 NodeList

Assigning Dojo Tooltip to a NodeList using 'selector' attribute

我想使用 https://dojotoolkit.org/reference-guide/1.10/dijit/Tooltip.html#attaching-to-multiple-nodes 中解释的示例将工具提示分配给多个节点。

但我想改为传递 NodesList。像这样:

new Tooltip({
  connectId: query('.list-container'),
  selector: query('.list-container-item'),
  getContent: function(matchedNode) {
    console.debug('this is a tooltip for ', matchedNode);
  }
});

不幸的是,这会抛出:TypeError: undefined is not a function

您需要 dojo/query 模块。
您还需要将 selector 属性 更改为如下所示的字符串。

new Tooltip({
  connectId: query('.list-container'),
  selector: '.list-container-item',
  getContent: function(matchedNode) {
    console.debug('this is a tooltip for ', matchedNode);
  }
});