jsTree 复选框插件错误
我有一个带有复选框的 jsTree,显示得很好。我可以打开 并关闭节点,选中和取消选中复选框等。
当我尝试获取所有已被选中的节点时,问题就出现了。 检查过。下面我列出了我尝试过的所有方法以及错误 当我尝试每一个时我都会收到消息。
$.tree.plugin.checkbox.get_checked($.tree.reference("#smuDomains"));
$.tree is undefined
$.jstree.plugin.checkbox.get_checked($.jstree.reference("#smuDomains"));
$.jstree.plugin.checkbox is undefined
$.tree.plugins.checkbox.get_checked($.tree.reference("#smuDomains"));
$.tree is undefined
$.jstree.plugins.checkbox.get_checked($.jstree.reference("#smuDomains"));
$.jstree.plugins is undefined
第二个($.jstree.plugin.checkbox)似乎得到了 最接近工作,但它似乎不喜欢“复选框” 参考。它应该是 check_box 还是不同的东西?
这是我用来初始化树的代码:
$.jstree._themes = "../script/css/jstree/themes/";
$("#smuDomains").jstree({
core : {},
themes : {
theme : "classic",
dots : true,
icons : true,
url : false
},
json_data : {
ajax : {
url : "[the url]",
datatype : "json",
data : function(n) {
return { id : n.attr ? n.attr("id") : 0 };
},
plugins : [ "themes", "json_data", "ui", "checkbox"]
});
});
I have a jsTree with checkboxes that shows up just fine. I can open
and close the nodes, check and uncheck the checkboxes, etc.
The problem comes in when I try to get all the nodes that have been
checked. Below I list all the ways I have tried, along with the error
messages I get when I try each one.
$.tree.plugin.checkbox.get_checked($.tree.reference("#smuDomains"));
$.tree is undefined
$.jstree.plugin.checkbox.get_checked($.jstree.reference("#smuDomains"));
$.jstree.plugin.checkbox is undefined
$.tree.plugins.checkbox.get_checked($.tree.reference("#smuDomains"));
$.tree is undefined
$.jstree.plugins.checkbox.get_checked($.jstree.reference("#smuDomains"));
$.jstree.plugins is undefined
The second one ($.jstree.plugin.checkbox) seems to be getting the
closest to working, but it doesn't seem to like the "checkbox"
reference. Should it be check_box or something different?
This is the code I use to init the tree:
$.jstree._themes = "../script/css/jstree/themes/";
$("#smuDomains").jstree({
core : {},
themes : {
theme : "classic",
dots : true,
icons : true,
url : false
},
json_data : {
ajax : {
url : "[the url]",
datatype : "json",
data : function(n) {
return { id : n.attr ? n.attr("id") : 0 };
},
plugins : [ "themes", "json_data", "ui", "checkbox"]
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我使用此代码在提交表单之前获取复选框:
I'm using this code to get checked boxes just before submit the form :
$('#tree').jstree('get_checked')
$('#tree').jstree('get_checked')
get_checked 的问题之一是它会在检查的父节点处停止。
我们最终采用了这样的方法:
$('#idOfDivContainingTree .jstree-checked')
这存在不适用于 jsTree 的未来版本的风险,因为它依赖于实现
one of the issues with get_checked is that it will stop at parent nodes that are checked.
We ended up going with something like this:
$('#idOfDivContainingTree .jstree-checked')
There is a risk of this not working with future versions of jsTree as it is dependent on the implementation
您可以:
checked_nodes = $("#smuDomains").jstree("get_checked", null, true);
$.each(checked_nodes, function(k, n) {
});
如果您只想要选定的节点,您可以:
selected_nodes = $("#smuDomains").jstree("get_selected", null, true);
希望有帮助
You can:
checked_nodes = $("#smuDomains").jstree("get_checked", null, true);
$.each(checked_nodes, function(k, n) {
});
if you want just the selected nodes, you can have:
selected_nodes = $("#smuDomains").jstree("get_selected", null, true);
hope it helps