在KendoUI / Angular中检索树节点文本

时间:2015-04-07 00:33:13

标签: angularjs kendo-ui

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); 
           });
      };

 }

1 个答案:

答案 0 :(得分:0)

您应该直接访问数据源:

$scope.queryTree = function(){
  var nodeDataItem = $scope.treeData.get($scope.sk);
  alert(nodeDataItem.text)
};

这是一个适合你的工作人员。 http://plnkr.co/edit/N4FYVh227HjvYOoWMYo4