加载后检查jstree复选框

ign*_*nas 12 jquery user-interface jquery-plugins 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;
        })
Run Code Online (Sandbox Code Playgroud)

有了这一切都没关系,但知道我无法找到任何地方如何检查树加载的复选框,例如,如果我使用jsTree像我的新闻项目的类别选择器当我创建新的新闻项目一切正常,当我想要更新该项我需要jsTree与选定的类别,这是我无法找到如何选择加载jsTree节点的任何示例.

对这个问题有任何帮助吗?

小智 8

如果您使用的是JSON_DATA,请添加class:jstree-checked到节点的attr对象:

{
  "data": "node name",
  "attr": { "id": "node id", "class":"jstree-checked" }
}
Run Code Online (Sandbox Code Playgroud)


Dev*_*per 5

对于当前的JSTREE版本3.2.1和JSON数据,我们需要使用状态:{已选中:true}

并添加到复选框的配置部分

“ checkbox”:{“ tie_selection”:false}

这个例子很好

data : [
            { "text" : "Root", state : { opened : true }, children : [

                { "text" : "Child 2", state : { checked : true },

]
Run Code Online (Sandbox Code Playgroud)


ign*_*nas 3

two_state我通过将复选框插件选项设置为 true找到了解决方案

"checkbox" => array(  "two_state" => true)
Run Code Online (Sandbox Code Playgroud)

然后如果您使用 Xml 数据,请添加class="jstree-checked"参数

一切都很好 :)

祝你好运 ;)