javascript 如何获取kendo ui grid中下拉列表的值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15067639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 23:22:00  来源:igfitidea点击:

How to get the value of the dropdown list in kendo ui grid?

javascripthtmlkendo-ui

提问by user123

I have a grid with dropdown and a checkbox. Whenever I have checked the checkbox (multi-select) I want to get the value of the drop downlist that is selected. How can I do that using kendoui.

我有一个带有下拉菜单和复选框的网格。每当我选中复选框(多选)时,我都想获取所选下拉列表的值。我怎么能用kendoui做到这一点。

Please help me here is my fiddle.

请帮助我,这是我的小提琴

And my code:

还有我的代码:

<div id="grid"></div>

<input type="button" value="gridSelectedItem" onclick="selectElementContents( document.getElementById('grid') );"
    />

<div>
<input id="dropdownList" runat="server" /></div>
<script type="text/x-kendo-template" id="CheckboxTemplate">
<li unselectable="off" class="k-item nowrap check-item">
    <input type="checkbox" name="#= text #" value="#= value #" class="check-input" #= selected ? "checked" : "" #/>
    <span>#= text #</span>
</li>

回答by Petur Subev

On a side not - The template that you have defined does not need to contain li element - it is generated automatically for you.

一方面不是 - 您定义的模板不需要包含 li 元素 - 它会自动为您生成。

To retrieve the model related to the item you can use the dataItem method of the ddl client object and the index of the option(that's why you need to fix your template because the index will be wrong).

要检索与项目相关的模型,您可以使用 ddl 客户端对象的 dataItem 方法和选项的索引(这就是您需要修复模板的原因,因为索引将是错误的)。

Here is the magical snippet:

这是神奇的片段:

var ddl = $('#dropdownList').data().kendoDropDownList;
var model = ddl.dataItem($input.closest('.k-item').index());
alert(model.text);

I updated your fiddleto see it in action.

我更新了你的小提琴以查看它的实际效果。

回答by t_plusplus

This does it for me:

这对我有用:

var selectedId = $('#MyDropDown').data("kendoDropDownList").value();

回答by Hedego

  1. The following code is for my shift kendo drop down:
  1. 以下代码用于我的班级剑道下拉菜单:

<div class="form-group">
  <label>Shift</label>
  <div class="input-group">
    @(Html.Kendo().DropDownListFor(t => t.ShiftId)
      .Name("ShiftId")
      .DataTextField("Text")
      .DataValueField("Value")
      .OptionLabel("...Select Shift...")
      .DataSource(source => source.Read(read => read.Action("GetShifts", "AssessmentResult")))
      .HtmlAttributes(new { style = "width:292px", @required = "required" })
    )
  </div>
</div>
  1. I have also button with on click event:
  1. 我也有点击事件的按钮:

<button type="button" id="show">Show</button>  
  1. The script is like the following which alerts the selected shift value (NB: I have done some research on Telerik Kedno Forum)
  1. 该脚本如下所示,它会提醒选定的班次值(注意:我在 Telerik Kedno 论坛上做了一些研究)

<script type="text/JavaScript">
  $('#show').click(function(event) {
    var ShiftId = $("#ShiftId").data("kendoDropDownList").value();            
    alert(ShiftId);

}

}