我在这里看到了答案,但我不明白attaching Tooltip to item without fixed element 'id'
我正在创建我的Dojo工具提示:
<script>
require(["dijit/Tooltip", "dojo/domReady!"], function(Tooltip){
new Tooltip({
connectId: ["div_1_1_2_1_1_1_2"],
label: "Please select a Country, Subsidiary before selecting a City."
});
new Tooltip({
connectId: ["div_1_1_2_1_2_1_2"],
label: "Please select a Country, Subsidiary before selecting a City."
});
});
</script>
我生成了div
个ID,所以我宁愿将工具提示绑定到另一个变量,例如我的属性:
data-viewid="Date_Time_Picker2"
这可能吗?
答案 0 :(得分:3)
您可以使用dojo/query
按属性查找节点。根据{{3}}文档,connectId可以是id或实际的dom节点引用。
HTML:
<body class="claro">
<div><span data-viewid="attachATooltipToMe">Test one</span>
</div>
<div> <span data-viewid="attachATooltipToMe">Test two</span>
</div>
<div> <span data-viewid="attachATooltipToMe">Test three</span>
</div>
</body>
JS:
require(['dojo/query', 'dijit/Tooltip', 'dojo/domReady!'], function (query, Tooltip) {
var nodes = query('[data-viewid="attachATooltipToMe"');
new Tooltip({
connectId: nodes,
label: "Please select a Country, Subsidiary before selecting a City."
});
});
这会将工具提示附加到每个节点,该节点具有使用值“attachATooltipToMe”指定的data-viewid属性。