【问题标题】:Getting text from value从值中获取文本
【发布时间】:2016-10-07 10:26:33
【问题描述】:

我有一个 Kendo DropDownList 并且我也已经分配了一个值。

从 jQuery 函数中,我有一个特定的值,我需要知道该值的文本。

有没有办法从值中获取文本??

我尝试了不同的方法,但没有奏效。

var tempvalue = 4;
$("#ddlDocType").data("kendoDropDownList").dataItem(tempvalue);

注意:我不想要选中的下拉列表文本。

【问题讨论】:

  • 请分享您的尝试。
  • var tempvalue = 4; $("#ddlDocType").data("kendoDropDownList").dataItem(tempvalue);这就是我尝试过的Jayesh。如果不能,请告诉我如何遍历剑道中下拉列表的项目。
  • 你可以分享你写的代码,我无法理解你真正想要做什么。
  • 有这方面的消息吗?

标签: jquery model-view-controller kendo-ui


【解决方案1】:

试试这个:

var getText = function(id) {
    var ddl = $("#ddl").data("kendoDropDownList"),
        result = ddl.dataItems().filter(function(item) {
            return item.id == id;
        });

    var text = "";

    if (result.length > 0) {
        text = result[0].text;
    }

    return text;
};

var text = getText(1); // id 1

Demo

【讨论】:

    【解决方案2】:

    dataItem 将返回 dataItem 对象。为了获取文本,您需要使用dataTextField 属性找出 kendoDropDownList 用于显示的字段是什么。

    var ddl = $("#ddlDocType").data("kendoDropDownList");
    var dataItem = ddl.dataItem(4);
    alert(dataItem[ddl.dataTextField]);
    

    如果您在初始化 kendoDropDownList 时没有为 dataTextField 指定值,我认为它会默认使用 text

    alert(dataItem.text);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-20
      • 2012-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多