【问题标题】:Can not set Kendo DropDownList selected value无法设置 Kendo DropDownList 选定值
【发布时间】:2018-03-16 12:59:39
【问题描述】:

我无法按照我想要的方式设置剑道下拉列表中的选定项目。 到目前为止,这是我尝试过的,但它似乎不起作用

<select name="YolTipleri" required
                data-value-primitive="true"
                data-role="dropdownlist"
                data-text-field="Adi"
                data-auto-bind="true"
                data-value-field="GID"
                data-source="Hede.Components.DataSources.YolTipi"></select>

我确实尝试过这样设置,但出现错误

$("#YolTipleri").data("kendoDropDownList").value(2);

它给了我错误

Uncaught TypeError: Cannot read property 'value' of undefined

如何设置这个值?

【问题讨论】:

  • 你看过documentation 的Kendo DropDownList 吗?
  • 是的,但是在动态数据绑定时我找不到所选项目的任何样本。

标签: javascript jquery kendo-ui


【解决方案1】:

如果你想要解决方案而不写 id 你可以使用它

$('[name="YolTipleri"]').data("kendoDropDownList").value(2);

【讨论】:

    【解决方案2】:

    这可能只是一个错字,但我有 kendo dojo 工作。

    在第一行中,您没有 id 选择器,而您在 jQuery 中使用了该选择器。

    对于MVVM 绑定和数据源,您可以使用data-bind 属性。

    <select id="YolTipleri" name="YolTipleri" required
        data-value-primitive="true"
        data-role="dropdownlist"
        data-text-field="Adi"
        data-auto-bind="true"
        data-value-field="GID"
        data-bind="source: source">
    </select>
    

    【讨论】:

      猜你喜欢
      • 2015-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-28
      • 2022-07-29
      • 2013-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多