jstree 复选框在加载时选中
我正在与 jQuery jsTree 插件复选框作斗争。好的,我已经了解如何处理选中或取消选中复选框的事件。如果它有用,我可以粘贴代码:
.bind("check_node.jstree", function(e, data)
{
if(data.rslt.obj !== undefined && data.rslt.obj.attr(\'id\') !== undefined)
{
jQuery.ajax({
async : false,
type: "POST",
dataType: "json",
url: "adsmanager/adsfields/ajaxappendcategory",
data:
{
"id" : data.rslt.obj.attr(\'id\'),
"itemId" : "' . Yii::app()->getRequest()->getParam('id') . '",
},
success: function(r)
{
if(r === undefined || r.status === undefined || !r.status)
{
data.rslt.obj.removeClass(\'jstree-checked\');
data.rslt.obj.addClass(\'jstree-unchecked\');
}
else
{
niceBox(\'ok\');
}
}
});
}
return true;
})
有了这个,一切都好,但我知道我无法在任何地方找到如何在树加载上选中复选框,例如,如果我在创建新新闻时为我的新闻项目使用类似 jsTree 的类别选择器item 一切正常,当我想更新该项目时,我需要带有选定类别的 jsTree,但我找不到任何示例如何在加载 jsTree 时选择节点。
这个问题有帮助吗?
I'm fighting with jQuery jsTree plugin checkbox. Ok, I have find out how to handle events on checking or unchecking checkbox. If its useful I can paste a code:
.bind("check_node.jstree", function(e, data)
{
if(data.rslt.obj !== undefined && data.rslt.obj.attr(\'id\') !== undefined)
{
jQuery.ajax({
async : false,
type: "POST",
dataType: "json",
url: "adsmanager/adsfields/ajaxappendcategory",
data:
{
"id" : data.rslt.obj.attr(\'id\'),
"itemId" : "' . Yii::app()->getRequest()->getParam('id') . '",
},
success: function(r)
{
if(r === undefined || r.status === undefined || !r.status)
{
data.rslt.obj.removeClass(\'jstree-checked\');
data.rslt.obj.addClass(\'jstree-unchecked\');
}
else
{
niceBox(\'ok\');
}
}
});
}
return true;
})
With this everything is ok, but know I cant find anywhere how to checked checkboxes on tree load, for example, if I'm using jsTree like category selector for my news Item when I create new news item everything is ok and when I want to update that item I need jsTree with selected categories and that's I cant find any example how to select nodes on loading jsTree.
Any help with this question?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果您使用 JSON_DATA,请将
class:jstree-checked
添加到节点的 attr 对象:If you are using JSON_DATA, add
class:jstree-checked
to the node's attr object:对于当前的 JSTREE 版本 3.2.1 和 JSON 数据,我们需要使用 state : {checked:true}
的配置
并添加到复选框部分“checkbox” :{
“tie_selection”:假
这个例子
工作正常
For current JSTREE version 3.2.1 and JSON data we need use state : { checked : true }
and add to config for checkbox section
"checkbox":{
"tie_selection": false
}
this example work fine
试试这个:
它对我有用。
以下是相关参考:
https://groups.google.com/forum/#!主题/jstree/bPv19DwQYFU
Try this:
It worked for me.
Here are related reference:
https://groups.google.com/forum/#!topic/jstree/bPv19DwQYFU
我通过将复选框插件选项
two_state
设置为 true 找到了解决方案,然后如果您使用 Xml 数据,则在参数中添加
class="jstree-checked"
一切都很好:)
好运气好;)
I have found the solution by setting checkbox plugin option
two_state
to trueand then if you are using Xml data add
class="jstree-checked"
in paramseverything fine :)
good luck ;)
为了完成上面的早期答案,至少使用最新的 v3.3.7,需要同时指定 state.selected 和 a_attr.class 才能将叶复选框初始化为使用复选框插件检查。这似乎解释了为什么 mytree.node_select("leafId") 函数单独不能以编程方式完成此操作,大概是因为子类属性也必须设置为 jstree_checked。
To complete earlier answers above, with latest v3.3.7 at least, the specification of BOTH state.selected and a_attr.class are required for a leaf checkbox to be initialized as checked with the checkbox plugin. This seems to explain why mytree.node_select("leafId") function alone does not accomplish this programatically, presumably because the child a class attribute also has to be set to jstree_checked.
也许这会对您有更多帮助 - 下面的 jstree v1
事件绑定
- 用于检查和取消检查 jstree服务器端 Asp.net MVC 的
May be this will help you more - jstree v1
below - for check and uncheck event bind for jstree
Server side Asp.net MVC
"state" : { "selected" : true }
选中复选框"state" : { "selected" : true }
Makes a checkbox selected试试这个:
查找数据:
Try this:
Find data:
节点各项使用状态-> selected:true 或 false 来选中或不选中复选框。
// 节点的预期格式(没有必填字段)
链接引用: https://www. jstree.com/docs/json/ ->转到“JSON 数据”选项卡
In each item of node use state -> selected: true or false to checked or not checkbox.
// Expected format of the node (there are no required fields)
Link references: https://www.jstree.com/docs/json/ -> go to "JSON data" tab