向 Dojo 树节点添加工具提示的最简单方法?
我已经看到了许多关于如何向 Dojo Tree 节点添加工具提示的建议,其中一些似乎不起作用,而另一些则让我提出其他问题...
有限成功的一种方法是:
var myTree = new dijit.Tree({
model: treeModel,
id: "myTree",
showRoot: false,
persist: false,
onClick: function(item){
console.log(item.name);
},
_onNodeMouseEnter : function(node, evt){
var tip = new dijit.Tooltip({
label: node.item.name,
connectId: [node.domNode.id]
});
}
});
我尝试过但取得 仅当来自树中较高的节点时,并且仅当您将鼠标从顶部边缘进入扩展时,才创建工具提示的奇怪行为...
第二次尝试,我查看了树的 onMouseEnter 方法,但它没有可以访问节点的数据项,等等我必须通过似乎有点逻辑的方式来获取项目数据...通过导航 DOM 树查找当前节点 id,然后在商店中查找该项目?...
最后我发现有树上的“getTooltip(item)”方法,但是当我设置它时:
var myTree = new dijit.Tree({
model: treeModel,
id: "myTree",
showRoot: false,
persist: false,
onClick: function(item){
console.log(item.Obi_Id);
},
getTooltip: function(item){
return item.Secondary_Names;
}
});
工具提示只是一个常规的HTML“标题”弹出窗口...
在动态(惰性)树上完成dojo工具提示的正确(简单)方法是什么节点? -罗比
I have seen a number of suggestions on how to add a tooltip to Dojo Tree node, and some don't seem to work and others have me asking other questions...
One way I have tried with limited success is this:
var myTree = new dijit.Tree({
model: treeModel,
id: "myTree",
showRoot: false,
persist: false,
onClick: function(item){
console.log(item.name);
},
_onNodeMouseEnter : function(node, evt){
var tip = new dijit.Tooltip({
label: node.item.name,
connectId: [node.domNode.id]
});
}
});
But it has the odd behavior of only creating the tooltip when coming from a node higher up in the tree, and only if you mouse into the expando from the top edge...
A second attempt I looked at the Tree's onMouseEnter method, but it doesn't have access to a node's data item, and so I would have to go through what seems a bit of logic to get the item data by ...looking up the current node id via navigating the DOM tree, then looking for that item in the store?...
Finally I discovered there is a 'getTooltip(item)' method on Tree, but when I set it up:
var myTree = new dijit.Tree({
model: treeModel,
id: "myTree",
showRoot: false,
persist: false,
onClick: function(item){
console.log(item.Obi_Id);
},
getTooltip: function(item){
return item.Secondary_Names;
}
});
the tooltip is just a regular HTML 'title' popup...
What is the correct (easy) way to accomplish dojo tooltips on dynamic (lazy) tree nodes?
-robbie
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是最简单的方法!
This is the easiest way!
您可以简单地使用
getTooltip
属性:You could simply use the
getTooltip
attribute:我以前没有享受过使用 Tree 的乐趣,但是您是否尝试过使用以下命令生成新的工具提示: http://dojotoolkit.org/reference-guide/dijit/Tooltip.html
I have not had the pleasure of working with Tree before, but have you tried spawning a new Tooltip using: http://dojotoolkit.org/reference-guide/dijit/Tooltip.html
您可以简单地使用 onMouseOver 事件并绑定到 Dijit 工具提示。
You can simply use the onMouseOver event and bind to that a Dijit Tooltip.