如何使用新数据重新加载Fuelux Tree

时间:2015-02-26 10:46:14

标签: ajax tree fuelux

此处我尝试使用Ace管理模板中的Fuelux Tree。我使用了他们使用的相同代码。

ace管理模板中使用的脚本代码:

jQuery(function($) {

var tree_data = {};
var sampleData = initiateDemoData(tree_data); //see below

$('#tree1')
    .ace_tree({
        dataSource: sampleData['dataSource1'],
        multiSelect: true,
        cacheItems: true,
        'open-icon': 'ace-icon tree-minus',
        'close-icon': 'ace-icon tree-plus',
        'selectable': true,
        'selected-icon': 'ace-icon fa fa-check',
        'unselected-icon': 'ace-icon fa fa-times',
        loadingHTML: '<div class="tree-loading"><i class="ace-icon fa fa-refresh fa-spin blue"></i></div>'
    });



function initiateDemoData(tree_data) {

    tree_data = {
        "2C27D744B956": {
            "text": "2C27D744B956",
            "children": {
                "001B179F4400": {
                    "text": "9991100003333",
                    "type": "item"
                },
                "9991100003333": {
                    "text": "9991100003333",
                    "type": "item"
                },
                "2c27d744b956": {
                    "text": "9991100003333",
                    "type": "item"
                },
                "002170615A04": {
                    "text": "9991100003333",
                    "type": "item"
                }
            },
            "type": "folder"
        }
    };

    var dataSource1 = function(options, callback) {
        var $data = null
        if (!("text" in options) && !("type" in options)) {
            $data = tree_data; //the root tree
            callback({
                data: $data
            });
            return;
        } else if ("type" in options && options.type == "folder") {
            if ("children" in options)
                $data = options.children || {};
            else
                $data = {} //no data
        }

        if ($data != null) //this setTimeout is only for mimicking some random delay
            setTimeout(function() {
            callback({
                data: $data
            });
        }, parseInt(Math.random() * 500) + 200);

        //we have used static data here
        //but you can retrieve your data dynamically from a server using ajax call
        //checkout examples/treeview.html and examples/treeview.js for more info
    }

    return {
        'dataSource1': dataSource1
    }
}

});

然后在按钮上单击我试图刷新树,使用来自ajax获取请求的新数据,但是当我尝试时,浏览器中出现错误,例如&#34; Uncaught TypeError:无法读取属性& #39;应用&#39;未定义&#34;。

以下是我的ajax代码:

$.ajax({
            type : "GET",
            url : "getDevices.htm?did=" + dID,
            success : function(data) {

                    tree_data = data; //tree_data is the data used for the treeview

                    $('#tree1').tree('reload');
            },
            error : function(data) {
                console.log("failure" + data);
            }
    });

请提供解决此问题的方法。 提前谢谢。

0 个答案:

没有答案