this plunk的目标是查询特定的树节点(假设其id存储在变量sk
中)并显示带有文本的警报。在输入字段中输入一个数字(节点sk
值),单击按钮,您将看到带有节点文本的警报。
分层数据源中的get
方法和hasChildren
无效,有什么想法吗?
HTML:
<div kendo-tree-view k-data-source="treeData"></div>
<br/><br/>
<button ng-click="queryTree()">Get Text</button>
<input ng-model="sk">
使用Javascript:
function MyCtrl($scope) {
$scope.sk = 3;
$scope.treeData = new kendo.data.HierarchicalDataSource({
data: [
{ sk: 11, text: "Furniture", expanded:true, items: [
{ sk: 2, text: "Tables & Chairs"},
{ sk: 3, text: "Sofas" },
{ sk: 4, text: "Occasional Furniture" }
] },
{ sk: 12, text: "Decor", expanded:true, items: [
{ sk: 6, text: "Bed Linen" },
{ sk: 7, text: "Curtains & Blinds" },
{ sk: 8, text: "Carpets" }
] }
],
schema: {
model: {
id: "sk",
hasChildren: function(item) {
return item.sk > 10;
}
}
}
});
$scope.queryTree = function(){
$scope.treeData.fetch(function() {
var dataItem = $scope.treeData.get($scope.sk);
alert(dataItem.text);
});
};
}
答案 0 :(得分:0)
您应该直接访问数据源:
$scope.queryTree = function(){
var nodeDataItem = $scope.treeData.get($scope.sk);
alert(nodeDataItem.text)
};
这是一个适合你的工作人员。 http://plnkr.co/edit/N4FYVh227HjvYOoWMYo4