我正在使用 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>");
});