如何使一些选定的项目在jstree中进行加载检查. (已选择=“已选择"无效) [英] How to make some selected items as checked on load in jstree. (selected = "selected" not working)
问题描述
在MVC 4中,我使用jstree.在创建操作中,我没有问题.但是在编辑"操作中,我将true
值设置为treemodel的某些项.型号就像:
In MVC 4 i use jstree. In create operation I have not problem. But in Edit operation, I set true
value to some items of treemodel. models are like:
public class RecursiveObject
{
public string data { get; set; }
public Int64 id { get; set; }
public FlatTreeAttribute attr { get; set; }
public List<RecursiveObject> children { get; set; }
}
public class FlatTreeAttribute
{
public string id;
public bool selected;
}
当我填充树模型时,我将selected = true;
设置为某些项目并在视图中使用它:
When I fill tree model, i set selected = true;
to some items and use this in view:
json_data: {
"ajax": {
url: "@Url.Action("GetTreeData", "MyController")",
type: "POST",
dataType: "json",
contentType: "application/json charset=utf-8"
}
},
但是在视图中,所有项目均未选中.我看到一些<li>
标记具有selected = "selected"
,但这并不影响它的检查.
But in view, all items are unchecked. I see some <li>
tags have selected = "selected"
, but this does not affect it's checking.
当我手动检查项目 时,jstree-unchecked
更改为jstree-checked
类.这意味着selected = "selected"
不起作用.
When I check item manually, jstree-unchecked
changes to jstree-checked
class. It means that selected = "selected"
does not work.
我该如何解决这个问题?
How can I solve this issue?
推荐答案
我找到了解决问题的方法.
I found solution for my question.
.bind("loaded.jstree", function (event, data) {
$('li[selected=selected]').each(function () {
$(this).removeClass('jstree-unchecked').addClass('jstree-checked');
});
});
这篇关于如何使一些选定的项目在jstree中进行加载检查. (已选择=“已选择"无效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!