admin管理员组文章数量:1394228
TL;DR - Is there a way to have working links in a jsTree node, without using JS redirection ?
I would like to add buttons inside a jsTree node, like this :
I used this code:
$('#tree').jstree({
'core': {
'multiple': false,
'themes': {
'responsive': false
}
}
});
/* custom */
body {
font: 14px/14px "Lucida Sans Unicode", "Lucida Grande", sans-serif normal;
}
.actions a {
background: #333;
color: #ccc;
font-size: 11px;
line-height: 18px;
border-radius: 4px;
padding: 0 5px;
text-decoration: none;
}
.actions a:hover {
background: #999;
}
<link href=".0.9/themes/default/style.min.css" rel="stylesheet"/>
<script src=".9.1/jquery.min.js"></script>
<script src=".0.1/jstree.min.js"></script>
<div id="tree">
<ul>
<li>
<span class="content">Folder</span>
<ul>
<li>
<span class="content">Subfolder</span>
<ul>
<li>
<span class="content">File</span>
<span class="actions">
<a href="/open">open</a>
<a href="/delete">delete</a>
</span>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
TL;DR - Is there a way to have working links in a jsTree node, without using JS redirection ?
I would like to add buttons inside a jsTree node, like this :
I used this code:
$('#tree').jstree({
'core': {
'multiple': false,
'themes': {
'responsive': false
}
}
});
/* custom */
body {
font: 14px/14px "Lucida Sans Unicode", "Lucida Grande", sans-serif normal;
}
.actions a {
background: #333;
color: #ccc;
font-size: 11px;
line-height: 18px;
border-radius: 4px;
padding: 0 5px;
text-decoration: none;
}
.actions a:hover {
background: #999;
}
<link href="https://cdnjs.cloudflare./ajax/libs/jstree/3.0.9/themes/default/style.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis./ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare./ajax/libs/jstree/3.0.1/jstree.min.js"></script>
<div id="tree">
<ul>
<li>
<span class="content">Folder</span>
<ul>
<li>
<span class="content">Subfolder</span>
<ul>
<li>
<span class="content">File</span>
<span class="actions">
<a href="/open">open</a>
<a href="/delete">delete</a>
</span>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
My problem is that jsTree create <a>
tags on each node (for a semantic purpose) and intercept every click
event. My own anchors are supposed to open a new page, but now nothing happens.
The author remends to listen the changed.jstree
event, and do the job myself :
$('#tree').on('changed.jstree', function (e, data) {
document.location = data.instance.get_node(data.selected[0], true).a_attr.href;
}).jstree();
This solution would be perfectly acceptable if I wanted to use JS redirection. But I don't.
Currently, I edited jsTree source code to avoid event interception (you can have a look on this rejected PR), but like the author mentioned it, this is not the good way to do it. So here is my final question :
Is there a way to have working links in a jsTree node, without using JS redirection ?
I'm open to any suggestion, I still can use to catch/trigger events, and my HTML markup can be reorganized.
Share Improve this question edited Feb 10, 2015 at 16:29 zessx asked Jun 16, 2014 at 9:05 zessxzessx 68.8k29 gold badges138 silver badges164 bronze badges2 Answers
Reset to default 5You can also try this:
$('#tree').on('ready.jstree', function () {
$('#tree').off("click.jstree", ".jstree-anchor");
})
Take a look here
Modify this plugin to your needs and then include it in your page and your plugins
config array.
You can even modify this to include the buttons inside the anchor (this example includes them in the list element), just make sure you include valid elements (use SPAN
or I
for example).
本文标签: javascriptClickable buttons inside a nodeStack Overflow
版权声明:本文标题:javascript - Clickable buttons inside a node - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744721785a2621736.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论