我在我的应用程序中使用kendo comboBox,我需要在ComboBox实际函数之外的ComboBox中获取记录的值和ID ....我在表中使用comboBox下拉列表对每条记录,所以我可以' t继承css ID以获取comboBox值...我已设法到达所选记录的输入组合框,我通过应用背景颜色进行了此测试。我测试过.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());
}
});
$("#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);
.....
答案 0 :(得分:3)
看看剑道demo,它实际上显示了你对什么感兴趣
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控件。考虑这个example:
$("#combobox").kendoComboBox({
dataSource: [ "Apples", "Oranges" ]
});
var combobox = $("#combobox").data("kendoComboBox");
combobox.value("Oranges");
因此,在您的情况下,请执行以下操作:
$(this).closest('table').find("._MarkSchemeId_Input").data("kendoComboBox").text()
答案 1 :(得分:2)
通过设计,ComboBox小部件将所有样式和CSS类从原始元素复制到可见输入。记录在案here。如果您检查呈现的HTML,它将如下所示:
<input class="custom-class" /> <script> $(function() { $(".custom-class").kendoComboBox(); }); </script>
<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 k-i-arrow-s" role="button" tabindex="-1"> select </span> </span> </span> <input class="custom-class" data-role="combobox" style="display: none;"> </span>
如您所见,自定义类被复制到包装器元素和可见输入。因此,您需要使用更具体的选择器来仅查找原始输入元素:
$(".custom-class[data-role=combobox]");
请注意,这将返回输入元素列表。如果需要获取选定的数据项,则需要循环它们并为每个输入元素获取组合框实例。
Here我准备了一个简单的jsBin演示,演示了如何实现这一目标。
答案 2 :(得分: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);