c1.documentReady(function () {
var theTree = wijmo.Control.getControl(
'#theTree'
);
theTree.itemsSource = getData();
theTree.displayMemberPath =
'header'
;
theTree.childItemsPath =
'items'
;
theTree.selectedItemChanged.addHandler(function (s, e) {
var btn = document.getElementById(
'btnRemove'
);
wijmo.setAttribute(btn,
'disabled'
, theTree.selectedItem ?
null
:
'disabled'
);
});
theTree.selectedItem = theTree.itemsSource[0];
document.getElementById(
'btnRemove'
).addEventListener(
'click'
, function () {
if
(theTree.selectedItem) {
var parent = theTree.selectedNode.parentNode;
var arr = parent
? parent.dataItem[theTree.childItemsPath]
: theTree.itemsSource;
var index = arr.indexOf(theTree.selectedItem);
arr.splice(index, 1);
theTree.loadTree();
}
});
function getData() {
return
[
{
header:
'Parent 1'
, items: [
{ header:
'Child 1.1'
},
{ header:
'Child 1.2'
},
{ header:
'Child 1.3'
}]
},
{
header:
'Parent 2'
, items: [
{ header:
'Child 2.1'
},
{ header:
'Child 2.2'
}]
},
{
header:
'Parent 3'
, items: [
{ header:
'Child 3.1'
}]
}
];
}
});