0

我在我的应用程序中使用剑道组合框,我需要在 ComboBox 实际功能之外从 ComboBox 中获取记录的值和 ID....获取组合框值...我已经设法输入所选记录的组合框,我通过对其应用背景颜色进行了此测试。我已经测试了 .val() ,它只适用于输入文本框,但它不适用于 kendo ComboBox ......

非常感谢

输入

  <td class="N_td">@Html.TextBox("Input_MarkingSchemeTitle_Element", null, new { id = @item.ElementID + "_EMST", @class = "ElementMarkingSchemeTitle k1-grid-input k-textbox_3 _MarkSchemeId_Input" })  </td>

组合框功能

 $("._MarkSchemeId_Input").kendoComboBox({
        minLength: 1,
        filter: 'contains',
        dataTextField: "Name",
        dataValueField: "ID",
        dataSource: {
            type: "json",
            serverFiltering: false,
            transport: {
                read: "/Qualification/GetAllMarkScheme_JSON"
            },
        },
        change: function () {

           alert("value " + this.value() + "   " + this.text());                      
        }
    });

jQuery函数

$("#ElementTable").on("click", ".k1-grid-confirm", function () {


   $(this).closest('table').find("._MarkSchemeId_Input").css("background", "red");

   var a1 = $(this).closest('table').find("._MarkSchemeId_Input").text(); // doesn't work

        alert("a1  " + a1);
 .....
4

3 回答 3

3

看看剑道演示,它实际上准确地显示了你对什么感兴趣

 var fabric = $("#fabric").data("kendoComboBox");
                var select = $("#size").data("kendoComboBox");
                $("#get").click(function() {
                    alert('Thank you! Your Choice is:\n\nFabric ID: ' +   fabric.value() + ' and Size: ' + select.value());
                });

您的示例中的值检索不起作用,因为您在 html 元素而不是 Kendo 控件处调用方法。考虑这个例子

$("#combobox").kendoComboBox({
  dataSource: [ "Apples", "Oranges" ]
});
var combobox = $("#combobox").data("kendoComboBox");
combobox.value("Oranges");

因此,在您的情况下,请执行以下操作:

$(this).closest('table').find("._MarkSchemeId_Input").data("kendoComboBox").text()
于 2014-04-01T09:32:23.150 回答
2

根据设计,ComboBox 小部件将所有样式和 CSS 类从原始元素复制到可见输入。这在此处记录。如果您检查呈现的 HTML,它将如下所示:

  • 原始元素+初始化代码
    <input class="custom-class" />
    <脚本>
        $(函数(){
            $(".custom-class").kendoComboBox();
        });
    </脚本>
  • 导致这个 HTML
    <span class="k-widget k-combobox k-header custom-class">
      <span tabindex="-1" unselectable="on" class="k-dropdown-wrap k-state-default">
        <input class="k-input custom-class" type="text" autocomplete="off" style="width: 100%;">
        <span tabindex="-1" unselectable="on" class="k-select">
          <span unselectable="on" class="k-icon ki-arrow-s" role="button" tabindex="-1">
            选择
          </span>
        </span>
      </span>
      <input class="custom-class" data-role="combobox" style="display: none;">
    </span>

如您所见,自定义类被复制到包装元素和可见输入。因此,您将需要使用更具体的选择器来仅查找原始输入元素:

$(".custom-class[data-role=combobox]");

请注意,这将返回输入元素的列表。如果需要获取选定的数据项,则需要循环它们并获取每个输入元素的组合框实例。

这里我准备了一个简单的 jsBin 演示,它展示了如何实现这一点。

于 2014-04-01T11:34:16.620 回答
1

我已设法解决以下问题

<td class="N_td">@Html.TextBox("Input_MarkingSchemeTitle_Element", null, new { id = @item.ElementID + "_EMST", @class = "ElementMarkingSchemeTitle k1-grid-input k-textbox_3 _MarkScheme_Input" })  </td>


 //--get all the MarkScheme from database and put in drop-down 
    $("._MarkScheme_Input").kendoComboBox({
        minLength: 1,
        filter: 'contains',
        dataTextField: "Name",
        dataValueField: "ID",
        dataSource: {
            type: "json",
            serverFiltering: false,
            transport: {
                read: "/Qualification/GetAllMarkScheme_JSON"
            },
        },
        change: function () {

           // alert("value " + this.value() + "   " + this.text());                      //if it need to test selected record data...    
      }
    });


 $("#ElementTable").on("click", ".k1-grid-confirm", function () {


        $(this).closest('table').find("._MarkScheme_Input").css("background", "red");

        //read all the input 'comboxBox' in loop...
        //var _comboBoxInput = $(this).closest('table').find("._MarkScheme_Input").filter("[data-role=combobox]");
        //_comboBoxInput.each(function (idx, input) {
        //    alert("idx " + idx + "  \n input " + input);
        //    var combobox = $(input).data("kendoComboBox");
        //    alert("ID>>>  : " + combobox.value() + ", Text: >>> " + combobox.text());
        //});

        //-------------------------
        var input = $(this).closest('table').find("._MarkScheme_Input");
        var comboboxInput = input.filter("[data-role=combobox]");
        var combobox = comboboxInput.data("kendoComboBox");
        var selectedText = combobox.text();
        var selectedValue = combobox.value();
        var dataItem = combobox.dataItem();

        alert("ID>>>  : " + selectedValue + ", Text: >>> " + selectedText);
于 2014-04-01T14:32:00.913 回答