如何从剑道组合框中获取价值 [英] How to get value from kendo combobox

查看:25
本文介绍了如何从剑道组合框中获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从剑道组合框值中获取?我总是对它没有定义..我使用过这些变体,但它们对我不起作用

How can I get from kendo combobox value? I always getting undefined on it.. I've used these variants, but they are not worked for me

var selected = $('#typesCombo').data('kendoComboBox').val();
var selected = $('#typesCombo').data('kendoComboBox').value();
var selected = $('#typesCombo').data('kendoComboBox');

并得到如下错误:Cannot read property 'val' of undefined

这是我的代码:

JS:

$('#loadContainer').load("@Url.Action("Load", "Home")" + id);

var selected = $('#typesCombo').data('kendoComboBox').val();

if (selected == '') {
    ...
    }

HTML:

@(Html.Kendo().ComboBoxFor(x => x.Types.Name).Name("typesCombo")
                                             .DataTextField("Name")
                                             .DataValueField("Id")
                                             .HtmlAttributes(new { style = "width:100%", id = "typesCombo" })
                                             .BindTo(Model.TypesList))

推荐答案

有很多方法可以获取小部件的选定值.如果您在初始化后尝试获取值并且它没有选择的值(在 index 参数)你会得到一个空值.如果您想在用户更改时获取该值,您可以使用 select 事件并得到这样的值:

There are many ways to get the widget selected value. If you are trying to get the value after it initialization and it has no selected value(declared in the index parameter) you will get an empty value. If you want to get the value when user changes it, you can use the select event and get the value like this:

$("#typesCombo").data('kendoComboBox').value(); // The selected value itself
$("#typesCombo").data('kendoComboBox').dataItem(); // The selected entire dataItem object
$("#typesCombo").val(); // Only if the target element is an input element

工作演示

这篇关于如何从剑道组合框中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆