【问题标题】:How to get both text and value from kendo combobox using TypesScript(angular)如何使用 Typescript(angular) 从剑道组合框中获取文本和值
【发布时间】:2020-06-04 17:58:28
【问题描述】:

我需要从 kendocombox 框 onchange 事件中获取文本和值。但我只能得到值字段。文本未显示。

HTML:

 <kendo-combobox [data]="taxRatesource" [placeholder]="'Select'" [textField]="'text'"
                 [valueField]="'value'" (valueChange)="taxRateGridChange($event)"
                 [(ngModel)]="datachild.intTaxRateCode">
                </kendo-combobox>

TS:

taxRateGridChange(event) {
const textVal = event;
}

const textVal 仅包含 value ,但也需要 text。 Kinldy 帮助解决这个问题。

【问题讨论】:

  • 一般情况下,选择或组合会返回所选选项的值。为什么您不尝试从数据源数组中查找选定的实体?

标签: angular typescript kendo-combobox


【解决方案1】:

通常选择或组合返回选定选项的值。但是您可以从数据源中找到选定的值。

  taxRateGridChange(value) {
    let textVal;
    if (value) {
      const selectedOption = this.dataSource.find((entity) => entity.value === value);
      textVal = selectedOption ? selectedOption.text : null;
    } else {
      textVal = null;
    }
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多