简体   繁体   English

如何在kendo ui网格中获取下拉列表的值?

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

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>

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 fiddle to see it in action. 我更新了您的小提琴以查看实际操作。

This does it for me: 这为我做到了:

var selectedId = $('#MyDropDown').data("kendoDropDownList").value(); var selectedId = $('#MyDropDown')。data(“ kendoDropDownList”)。value();
  1. The following code is for my shift kendo drop down: 以下代码适用于我的shift kendo下拉菜单:

<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: 我也有点击事件按钮:

<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) 该脚本类似于以下内容,它会警告选定的移位值(注意:我已经在Telerik Kedno论坛上进行了一些研究)

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

} }

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

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