简体   繁体   English

剑道树列表展开事件

[英]kendo treelist expand event

In my Kendo UI treelist, I'd like to capture the currently-expanded row in the expand event, then check if its children rows are leaf nodes. 在我的Kendo UI树形列表中,我想捕获expand事件中当前扩展的行,然后检查其子行是否为叶节点。 If they are leaf nodes, I'd like to remove the font-weight: bold; 如果它们是叶节点,我想删除font-weight: bold; style attribute. 样式属性。

Here is a snippet showing the treeOptions object. 这是显示treeOptions对象的代码段。 At this expand event, it's easy to know that there are children nodes, but how can I tell if those children nodes has have children or not ? 在这个expand事件中,很容易知道有子节点,但是我怎么知道那些子节点是否有子节点呢? ie are they leaf nodes ? 即它们是叶节点吗?

  var treeOptions = { dataSource: ds, columns: colDefs, selectable: true, height: 320, change: function (e) { var selectedRow = this.select(); var row = this.dataItem(selectedRow); }, expand: function (e) { var row = e.model; var hasChildren = row.hasChildren; var uid = row.uid; } }; 

And here is the Kendo API doc I'm reading through. 这是我正在阅读的Kendo API文档。

thanks in advance, Bob 预先感谢,鲍勃

I haven't found any method to do that in the doc either, the only way i can think of it right now is by looping through datasource and get the all of the children element that match the parent id of the expanded element. 我也没有在文档中找到任何执行此操作的方法,我现在唯一想到的方法是循环遍历数据源并获取与扩展元素的父ID匹配的所有子元素。 Then you can see if it's 'hasChildren' attribute. 然后,您可以查看它是否为'hasChildren'属性。

expand: function(e) {
  //get the widget datasource then loop to match the parent id of the expanded element
  var data =this.dataSource.data();
  var children = [];
  for(i=0; i<data.length; i++){
      if(data[i].parentId == e.model.id){
      children.push(data[i]);
    }
  }


  //do chose which children you want to see its "hasChildrenStatus"
  console.log(children[0].hasChildren);
  console.log(children[1].hasChildren);

  //do remove css by using it's uid to get the element

}

Kendo dojo example 剑道道场示例

Here is one way. 这是一种方法。 Get the dataSource view and iterate through all the rows. 获取dataSource视图并遍历所有行。 Find the ones whose parentid is equal to the current row id and use the uid to update the DOM element: 查找其父ID等于当前行ID的那些,并使用uid更新DOM元素:

expand: function (e) {
  var id = e.model.id;
  if (!e.model.hasChildren) return; 

  var dataSourceView = $(this)[0].dataSource._view;
  for (var i=0; i<dataSourceView.length; i++){
    var pid =  dataSourceView[i].parentId;

    var Children = dataSourceView[i].hasChildren;
    if (pid == id && !Children){                              
         var uid = dataSourceView[i].uid;
       $('[data-uid="' + uid + '"]').css("font-weight", "bold");
    }

  }
}

DEMO 演示

if you make the treelist selectable, than you can use the click event 如果将树形列表设为可选择状态,则可以使用click事件

$("#treeList).on("click","tr[role='row']",function(e){
    var row = $(e.target).closest("tr[role='row']");
        })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM