加载时选中了jstree复选框 [英] jstree checkbox checked on load

查看:191
本文介绍了加载时选中了jstree复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery 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;
        })

有了这个,一切都很好,但是知道我在任何地方都找不到如何检查树负载的复选框,例如,如果我在创建新的新闻项时对我的新闻项使用类似jsTree的类别选择器,那么一切正常,何时我想更新该项目,我需要具有选定类别的jsTree,这是我找不到任何示例如何在加载jsTree时选择节点.

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.

这个问题有帮助吗?

推荐答案

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

If you are using JSON_DATA, add class:jstree-checked to the node's attr object:

{
  "data": "node name",
  "attr": { "id": "node id", "class":"jstree-checked" }
}

这篇关于加载时选中了jstree复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆