向 Dojo 树节点添加工具提示的最简单方法?

发布于 2024-11-16 12:26:00 字数 1551 浏览 0 评论 0原文

我已经看到了许多关于如何向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

晨与橙与城 2024-11-23 12:26:00

这是最简单的方法!

var myTree = new dijit.Tree({
    model: treeModel,
    id: "myTree",
    showRoot: false,
    persist: false,
    onClick: function(item){                                                
       console.log(item.name);
    },
    _onNodeMouseEnter: function (node,evt) {
       dijit.showTooltip(node.item.name,node.domNode)
    },
    _onNodeMouseLeave: function (node,evt) {
       dijit.hideTooltip(node.domNode);
    },
});

This is the easiest way!

var myTree = new dijit.Tree({
    model: treeModel,
    id: "myTree",
    showRoot: false,
    persist: false,
    onClick: function(item){                                                
       console.log(item.name);
    },
    _onNodeMouseEnter: function (node,evt) {
       dijit.showTooltip(node.item.name,node.domNode)
    },
    _onNodeMouseLeave: function (node,evt) {
       dijit.hideTooltip(node.domNode);
    },
});
浮世清欢 2024-11-23 12:26:00

您可以简单地使用 getTooltip 属性:

new Tree
({ 
    model: model, 
    getTooltip: function(item) { return "A tooltip!"; }
});

You could simply use the getTooltip attribute:

new Tree
({ 
    model: model, 
    getTooltip: function(item) { return "A tooltip!"; }
});
妥活 2024-11-23 12:26:00
define(["dojo/aspect","dijit/Tree","dijit/Tooltip"] ,function(aspect,dijit_Tree,dijit_Tooltip) {
    var tree=new dijit_Tree({....});

    //dijit.showTooltip dijit.hideTooltip defined in Tooltip.js

    //copied from dndContainer.js:
    // aspect.after(this.tree, "_onNodeMouseEnter", lang.hitch(this, "onMouseOver"), true)

    var ttf_on=function(node,evt){dijit.showTooltip("Rev="+node.item.latestRevision,node.domNode)};

    var ttf_off=function(node,evt){dijit.hideTooltip(node.domNode);};

    aspect.after(tree,"_onNodeMouseEnter",ttf_on,true);
    aspect.after(tree,"_onNodeMouseLeave",ttf_off,true);
}
define(["dojo/aspect","dijit/Tree","dijit/Tooltip"] ,function(aspect,dijit_Tree,dijit_Tooltip) {
    var tree=new dijit_Tree({....});

    //dijit.showTooltip dijit.hideTooltip defined in Tooltip.js

    //copied from dndContainer.js:
    // aspect.after(this.tree, "_onNodeMouseEnter", lang.hitch(this, "onMouseOver"), true)

    var ttf_on=function(node,evt){dijit.showTooltip("Rev="+node.item.latestRevision,node.domNode)};

    var ttf_off=function(node,evt){dijit.hideTooltip(node.domNode);};

    aspect.after(tree,"_onNodeMouseEnter",ttf_on,true);
    aspect.after(tree,"_onNodeMouseLeave",ttf_off,true);
}
撩心不撩汉 2024-11-23 12:26:00

我以前没有享受过使用 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

Saygoodbye 2024-11-23 12:26:00

您可以简单地使用 onMouseOver 事件并绑定到 Dijit 工具提示。

    new Tree({ 
        model: model, 
        onMouseOut: function(e){ 
            var node = dijit.getEnclosingWidget(e.target);
            Tooltip.hide(node.labelNode); 
        },
        onMouseOver: function(e) {
            var node = dijit.getEnclosingWidget(e.target);
            Tooltip.show("A tooltip!", node.labelNode);
        }
    }); 

You can simply use the onMouseOver event and bind to that a Dijit Tooltip.

    new Tree({ 
        model: model, 
        onMouseOut: function(e){ 
            var node = dijit.getEnclosingWidget(e.target);
            Tooltip.hide(node.labelNode); 
        },
        onMouseOver: function(e) {
            var node = dijit.getEnclosingWidget(e.target);
            Tooltip.show("A tooltip!", node.labelNode);
        }
    }); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文