May Abughazaleh
May Abughazaleh

Reputation: 3

how i can prevent reload sub folder of same parent FuelUX Tree

var DataSourceTree = function (options) {
                this.url = options.url;
            }
            DataSourceTree.prototype = {
                data: function (options, callback) {
                    var self = this;
                    var $data = null;
                    var param = null
                    if (!("name" in options) && !("type" in options)) {
                        param = 0; //load the first level  
                    } else if ("type" in options && options.type == "folder") {
                        if ("additionalParameters" in options && "children" in options.additionalParameters) {
                            param = options.additionalParameters["id"];
                        }
                    }
                    if (param != null) {
                        $.ajax({
                            url: this.url,
                            data: 'id=' + param,
                            type: 'POST',
                            dataType: 'json',
                            success: function (response) {
                                callback(response)
                            },
                            error: function (response) {
                                console.log(response);
                            }
                        })
                    }
                }
            };
            $('#tree2').admin_tree({
                dataSource: new DataSourceTree({ url: 'AccountTree.ashx' }),
                loadingHTML: '<div class="tree-loading"><i class="fa fa-spinner fa-2x fa-spin"></i></div>',
                'open-icon': 'fa-folder-open',
                'close-icon': 'fa-folder',
                'selectable': false,
                'multiSelect': false,
                'selected-icon': null,
                'unselected-icon': null
            });

this JSON data i revived from AccountTree.ashx {\"data\":[{\"id\":1,\"name\":\"label 1\",\"type\":\"folder\",\"additionalParameters\":{\"id\":1,\"children\":true,\"itemSelected\":false,\"name\":\"test\",\"type\":\"item\"}}]}

i know there is something wrong in callback(response)

https://i.sstatic.net/6DEtr.png

must be label1 --> item

Upvotes: 0

Views: 269

Answers (1)

Interactive Llama
Interactive Llama

Reputation: 780

It seems that your data source function is not changing the URL you are getting JSON from.

When a folder node is opened it uses whatever JSON the datasource gives it. Use the attr key and the event opened.fu.tree to give your nodes data attributes that will then inform/manipulate your datasource and tell it what URL and thus JSON to load.

Upvotes: 0

Related Questions