Kendo UI Web – DropDownList:选择事件未正确返回选定值

我绑定一个DropDownList小部件来select事件:

 var items = [ { text: 'Item 3', value: '3' }, { text: 'Item 4', value: '4' } ]; var dropDownListEl = $('#dropdownlist'); dropDownListEl.kendoDropDownList({ dataTextField: 'text', dataValueField: 'value', index: 0 }); var kDropDownList = dropDownListEl.data('kendoDropDownList'), ds = kDropDownList.dataSource; items.forEach(function (item) { ds.add(item); }); kDropDownList.bind('select', function (e) { console.log('this.value(): ' + this.value()); }); 

但是,当我进行选择时,它不会返回正确的值。

我一直在尝试几乎所有的可能性,没有一个工作。 http://jsfiddle.net/glenn/gxJ3S/

这让我疯了!

绑定选择 Kendo DropDownList的 事件 ,如下所示,以获得正确的选定项目

  kDropDownList.bind('select', function (e) { var dataItem = this.dataItem(e.item.index()); console.log('this.value(): ' + dataItem.value); }); 

这是工作的JSFiddle

相反,使用改变事件,它更直接

 .. change: function(e) { var value = this.value(); // Use the value of the widget } .. 
 var _item = e.sender.dataItem(e.sender.selectedIndex); 

我认为剑道改变了他们的API:

重要提示:自2015年第1季度(2015.1.318)版本起,选项标签已移至项目列表DOM集合之外。 因此,jQuery.index()不再可用于可靠地检测选项标签是否为选定的下拉项。

参考。 http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist#events-select

最终,这是唯一对我有用的东西:

 var item = e.sender.dataItem(e.item) 

如果您使用角度,您可以使用以下选项获取所选项目: e.sender.dataItem(e.item.index())