曾用到这个fancytree插件,找了好久才找到这个自动选中的源码
if ($("entityTree") != null) {
$(function () {
// Create
the tree inside the <div id="tree"> element.
$("#entityTree").fancytree({
source: { url: "/Home/GetTreeViewData",
cache: true }
, checkbox: true
, icons: false
, cache: true
, lazyLoad: function (event, data) {
var node = data.node;
data.result = {
url:
"/Home/GetTreeViewData/" +
node.key.replace(node.data.idPrefix, "")
, data: { mode:
"children", parent: node.key }
, cache: true
};
}
, renderNode: function (event, data) {
// Optionally tweak data.node.span
var node = data.node;
var $span = $(node.span);
if (node.key !=
"_statusNode") {
$span.find("> span.fancytree-expander").css({
borderLeft: node.data.customLeftBorder
//borderLeft: "1px solid orange"
});
}
}
, selectMode: 3
, select: function (event, data) {
var node = data.node;
if (node.isSelected()) {
if (node.isUndefined()) {
// Load
and select all child nodes
node.load().done(function () {
node.visit(function (childNode) {
childNode.setSelected(true);
});
});
} else {
// Select
all child nodes
node.visit(function (childNode) {
childNode.setSelected(true);
});
}
}
else {
//this only works when
you click the specific node
delMarker(node.key);
}
// Get a list of all selected nodes,
and add markers
var selKeys =
$.map(data.tree.getSelectedNodes(), function (node) {
if
(node.data.treeItemType == "ent") {
if
(markers[node.key] == null) {
addMarker(node.key, node.data.lat, node.data.lng,
node.desc, node.data.image, node.title, node.data.childImage);
}
}
});
alert("selected");
}
, strings: {
loading: "Grabbing places and events…",
loadError: "Load error!"
}
})
});
}
本站(PHP --> Golang)已重构,代码开源
当你能力不能满足你的野心的时候,你就该沉下心来学习