简体   繁体   English

启用复选框时如何从 KendoDropDowntree 获取选定的数据项?

[英]How to get the Selected Data Items from KendoDropDowntree when checkboxes is enabled?

I am using kendo dropdowntree with checkboxes enabled.我正在使用启用复选框的剑道下拉树。 I need to get the entire data item of the selected nodes when the change is triggered.触发更改时,我需要获取所选节点的整个数据项。 Currently, I'm getting only the Value field of the selected Items.目前,我只获得所选项目的值字段。 How to get the entire Item?如何获得整个项目?

<script>
$("#dropdowntree").kendoDropDownTree({
 dataSource: [{ text: "item1", value: 1 }, { text: "item2", value: 2 },{ text: "item3", value: 3 }],
 checkboxes: true,
 change: function(e) {
   var value = this.value();
   // Here I need the checked dataItems as full objects, instead of just values
 }
});
</script>

Unfortunately it does not appear as though Kendo exposes the selected dataItems, so you will need to do it manually.不幸的是,Kendo 似乎没有公开选定的数据项,因此您需要手动进行。

The parameter e exposes the widget that triggered the event via e.sender .参数e公开了通过e.sender触发事件的小部件。 From there you can filter the widget's dataSource by the value returned by this.value .从那里您可以通过this.value返回的值过滤小部件的数据源。

Take a look at this example:看看这个例子:

change: function(e) {
  var value = this.value();
  var dataSource = e.sender.dataSource;
  var dataItems = e.sender.dataSource.data().filter(dataItem => value.indexOf(dataItem.value) > -1);
  console.log(dataItems);
}

Fiddle: https://dojo.telerik.com/eKaFojav小提琴: https://dojo.telerik.com/eKaFojav

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

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