Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

valid_children не фильтрует запрещенные типы #20

Closed
aleskovets opened this issue May 26, 2011 · 1 comment
Closed

Comments

@aleskovets
Copy link

Приветствую, Иван.
Я слегка изменил пример таким образом чтобы рутами могли быть только ноды типа "folder":
Но в результате ноды типа "question" все еще пытаются развернуться, несмотря на "valid_children" : "none". При этом видно, что картинка подцепилась (404.png ведет "вникуда") Использую jsTree 1.0-rc3:

$(function () {
        $("#tree").jstree({ 
            // List of active plugins
            "plugins" : [ 
                "json_data", "themes", "types"
            ],
            // the core plugin - not many options here
            "core" : {
            },
            // I usually configure the plugin that handles the data first
            // This example uses JSON as it is most common
            "json_data" : {
                // This tree is ajax enabled - as this is most common, and maybe a bit more complex
                // All the options are almost the same as jQuery's AJAX (read the docs)
                "ajax" : {
                    // the URL to fetch the data
                    "url" : "@{Tree.getChildren()}",
                    // the `data` function is executed in the instance's scope
                    // the parameter is the node being loaded 
                    // (may be -1, 0, or undefined when loading the root nodes)
                    "data" : function (n) { 
                        // the result is fed to the AJAX request `data` option
                        return {
                            "id" : n.attr ? n.attr("id").replace("node_","") : -1
                        }; 
                    }
                }
            },
            // Using types - most of the time this is an overkill
            // read the docs carefully to decide whether you need types
            "types" : {
                // I set both options to -2, as I do not need depth and children count checking
                // Those two checks may slow jstree a lot, so use only when needed
                "max_depth" : -2,
                "max_children" : -2,
                // I want only `folder` nodes to be root nodes 
                // This will prevent moving or creating any other type as a root node
                "valid_children" : [ "folder" ],
                "types" : {
                    // The question type
                    "question" : {
                        // I want this type to have no children (so only leaf nodes)
                        // In my case - those are questions
                        "valid_children" : "none",
                        "icon" : {
                            "image" : "404.png"
                        }
                    },
                    // The `folder` type
                    "folder" : {
                        // can have questions and other folders inside of it
                        "valid_children" : [ "question", "folder" ]
                    }
                }
            }
        });

    });

Пример передаваемого json для второго уровня:
[{"data":"test","attr":{"id":"1","rel":"question"},"state":"closed"},{"data":"123","attr":{"id":"2","rel":"question"},"state":"closed"}]

хостинг изображений

@vakata
Copy link
Owner

vakata commented Jul 11, 2011

Sorry, but my Russian is very bad :) I understood what you mean ... but I cannot answer in russian ... Use "./404.png" as mentioned in the docs.
As for valid children - it will not filter out the nodes that are already there, but will prevent the user from moving or creating new ones.

@vakata vakata closed this as completed Jul 11, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants