【问题标题】:How to set Default value for kendo-combobox in angular 2如何在角度 2 中设置 kendo-combobox 的默认值
【发布时间】:2017-07-04 10:34:59
【问题描述】:

我正在使用Kendo Combobox在UI中绑定某些值。是否可以将Array的第一个值设置为默认值?.

【问题讨论】:

  • 发布您的代码 sn-p。如何将组合框初始化为选择标记并为其分配值。

标签: angular2-template kendo-combobox


【解决方案1】:

从组合框的角度来看,您可以使用以下代码添加第一个值作为选择。这与 Angular 代码无关。因为你没有提到任何代码 sn-p 或你想用来实现这一点的功能。

$("#targetComboId").kendoComboBox({
    dataTextField: "text",
    dataValueField: "value",
    dataSource: [{
            text: "Cotton",
            value: "1"
        },
        {
            text: "Polyester",
            value: "2"
        },
        {
            text: "Cotton/Polyester",
            value: "3"
        },
        {
            text: "Rib Knit",
            value: "4"
        }
    ],
    index: 0 // Your target value, set it to the index you want
});

这将选择并填充组合框中的第一个值。希望对您有所帮助!

【讨论】:

    【解决方案2】:

    我知道这对你来说已经晚了,其他人可以使用它。

    这是在客户端的 .html 文件中:

    <kendo-combobox  [data]="SalasType" [valuePrimitive]="true"
              [textField]="'name'" (valueChange)="productTypeChange($event)" [valueField]="'id'" [(ngModel)]="selectedValue.id" name="Product Group">
            </kendo-combobox>
    

    将此添加到客户端 .ts 文件中: 在公共文件中添加这个(或者你可以在你的 .ts 中创建这个数组)

    export const OSSSALELIST = [
      { id: 1, name: 'Product Group' },
      { id: 2, name: 'Product' }
    ];
    

    在此处调用该全局常量,

      SalasType = OSSSALELIST;
      selectedValue:any;
    

    在 oninit 方法中:enter code here

    this.selectedValue=this.SalasType[0];
    

    【讨论】:

      猜你喜欢
      • 2017-07-22
      • 1970-01-01
      • 2017-05-24
      • 2020-11-14
      • 1970-01-01
      • 2020-04-21
      • 2011-12-22
      • 1970-01-01
      • 2020-08-07
      相关资源
      最近更新 更多