asp.net-mvc 我如何从剑道组合框中获得选择值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21907506/
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
how i get select value from kendo comboBox
提问by Toxic
i have implented Kendo ComboBox but struggling to get selected value ....
我已经实施了 Kendo ComboBox,但正在努力获得选定的价值......
$("#_FeeScheme_Input").kendoComboBox({
minLength: 1,
filter: 'contains',
dataTextField: "FeeSchemeDescription",
dataValueField: "FeeSchemeID",
select: onSelect,
dataSource: {
type: "json",
serverFiltering: false,
transport: {
read: "/Qualification/GetAllFeeScheme_JSON"
},
}
});
...
...
function onSelect(e) {
var dataItem = this.dataItem(e.item.index());
alert("value " + dataItem.text); //NOT WORKING... RETURN NULL VALUE
};
Razor code
剃刀代码
<div class="form-group">
@Html.LabelFor(model => model._FeeScheme.FeeSchemeDescription, new { @class = "control-label col-md-3" })
<div class="col-md-6">
@Html.TextBoxFor(model => model._FeeScheme.FeeSchemeDescription, new { id = "_FeeScheme_Input" })
@Html.ValidationMessageFor(model => model._FeeScheme.FeeSchemeDescription)
</div>
</div>
采纳答案by Adrian Salazar
The getters/setters from the kendo comboBox are part of the kendoComboBox 'class'.
来自 kendo comboBox 的 getter/setter 是 kendoComboBox 'class' 的一部分。
You can use this.value()or this.text()depending on what you need.
您可以根据需要使用this.value()或this.text()。
$("#_FeeScheme_Input").kendoComboBox({
minLength: 1,
filter: 'contains',
dataTextField: "FeeSchemeDescription",
dataValueField: "FeeSchemeID",
dataSource: {
type: "json",
serverFiltering: false,
transport: {
read: "/Qualification/GetAllFeeScheme_JSON"
},
},
change: function(){
alert("value " + this.value());
}
});
回答by Zolfaghari
var c = $('#MyCombo');
// to get selected id
c.val() // and also
c.data('kendoComboBox').value()
// to get selected text
c.data('kendoComboBox').text()
// to get selected item index
c.data('kendoComboBox').select()
// to set selected item e.g. 3
c.data('kendoComboBox').select(2)
回答by MustafaP
You can use jquery too, If you try to take value out of events.
如果您尝试从事件中获取价值,您也可以使用 jquery。
var CB= $("#_FeeScheme_Input").data("kendoComboBox");
var description= CB.dataItem(CB.select()).FeeSchemeDescription; // for text field
alert(description);
var CB= $("#_FeeScheme_Input").data("kendoComboBox");
var Id= CB.dataItem(CB.select()).FeeSchemeID; // for value field
alert(Id);
回答by Vivek Parekh
This answer might help
这个答案可能有帮助
Kendo combobox.value(x) not working correctly
And
和
回答by Paul Gorbas
You can also use jquery to get the ID and value like so:
您还可以使用 jquery 获取 ID 和值,如下所示:
First off give your comboBox a name:
首先给你的组合框起一个名字:
$("#_FeeScheme_Input").kendoComboBox({
Name: 'MyComboBox',
minLength: 1,
...
Then you can get the ID and Value like this:
然后你可以像这样获得 ID 和 Value:
var myId = $("#MyComboBox").val();
var myText = $("#MyComboBox").data('kendoComboBox').text();

