jstree select_limit not working. I want to set selection limit to select only 3 nodes

耗尽温柔 提交于 2019-12-12 07:26:52

问题


My jstree function is here.
I have set 'select_limit' : 3, but is not working. when I run, I am able to select more than 3 nodes, but I need to select no more than 3 nodes.

    j1("#utree_activity").jstree({
        "plugins": ["themes", "html_data", "ui", "crrm", "checkbox"],
        "html_data": {
            "ajax": {
                "url": urlGlobal + "jstrees/activitytree/",
                "asynchronous": "false",
                "data": function (n) {

                    return {
                        id: n.attr ? n.attr("id") : 0,
                        default_activities: default_activities
                    };
                },
                "success": function (gb) {

                },

            }
        },
        "ui": {
            "select_limit": 3,
        },

        "cookies": {
            cookie_options: {
                path: "/"
            }
        },

        "checkbox": {
            two_state: true,
            real_checkboxes: false
        }
    });

回答1:


select_limit doens't handle checkbox you must roll your own before.jstree method.

j1.bind("before.jstree", function (e, data) {
    if (data.func === "check_node") {
        if (j1.jstree('get_checked').length >= 1) {
            e.preventDefault();
            return false;                
        }
    }
});

Note that this code if for example only, and doesn't handle child nodes

Working fiddle: http://jsfiddle.net/cfb9J/1/




回答2:


There is another option missing, probably need to add the ui module, try this:

j1("#utree_activity").jstree({ 
"plugins" : ["html_data","ui"],

 //the rest of your code
});


来源:https://stackoverflow.com/questions/14785236/jstree-select-limit-not-working-i-want-to-set-selection-limit-to-select-only-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!