jqwidgets树id

时间:2013-01-18 16:07:36

标签: ajax jquery-ui jquery

我正在使用jqxwidgets,并且我试图让树中的li id成为我通过json传递的项目的id。目前,项目的ID类似于:treeItem9905728103457950000

<script type="text/javascript">

var url = "university/list"
var data = jQuery.parseJSON(
    jQuery.ajax({
        url: url, 
        async: false,
        dataType: 'json'
    }).responseText
);
var builddata = function () {
var source = [];
var items = [];
// build hierarchical source.
for (i = 0; i < data.length; i++) {
    var item = data[i];
    var label = item["text"];
    var parentid = item["parentid"];
    var id = item["id"];

    if (items[parentid]) {
        var item = { parentid: parentid, label: label, item: item };
        if (!items[parentid].items) {
            items[parentid].items = [];
        }
        items[parentid].items[items[parentid].items.length] = item;
        items[id] = item;
    }
    else {
        items[id] = { parentid: parentid, label: label, item: item };
        source[id] = items[id];
    }
}
return source;
}

var source = builddata();
// create jqxTree
$('#jqxTree').jqxTree({ source: source, width: '300px' });
$('#jqxTree').bind('select', function (event) {
        $("#west-container").html("<div style='margin: 10px;'>" +     event.args.element.id + "</div>");
});

1 个答案:

答案 0 :(得分:0)

我能够将id添加到items数组中:

var item = { parentid: parentid, label: label, item: item, id:id };

items[id] = { parentid: parentid, label: label, item: item, id:id };