Angular 6 kendo-dropdownlist有条件地设置[valueField]和[textField]

时间:2019-06-12 15:17:30

标签: angular kendo-ui conditional-statements textfield

我在Angular 6项目中有一个kendo-dropdownlist,需要根据条件从两个不同的数据集中进行填充。我在弄清楚如何根据条件设置[valueField]和[textField]时遇到困难

   <kendo-dropdownlist id="UP_CM_IN" name="UP_CM_IN"
            style="width:90%"
            [(ngModel)]="SelectUP_CM_IN"
            [defaultItem]="defaultUP_CM_IN"
            [data]="UP_CM_IN"
            [filterable]="true"
            *ngIf="selectedCS=='CM' ? [valueField]='CD_IN': [valueField]='UP_IN'"
            *ngIf="selectedCS=='CM' ? [textField]='CD_IN': [textField]='UP_IN'"
            (valueChange)="handleUP_CM_INChange($event)"
            (filterChange)="handleUP_CM_INFilter($event)">
    </kendo-dropdownlist>

1 个答案:

答案 0 :(得分:1)

我认为可能无法仅根据条件更改数据集。  但是您可以做的是...用不同的数据集创建2个下拉元素,并使用* ngIf指令有条件地在Dom上显示它们...

示例:

<kendo-dropdownlist *ngIf="selectedCS=='CM'" id="UP_CM_IN" name="UP_CM_IN"
            style="width:90%"
            [(ngModel)]="SelectUP_CM_IN"
            [defaultItem]="defaultUP_CM_IN"
            [data]="UP_CM_IN"
            [filterable]="true"
            [valueField]='CD_IN': 
            [textField]='UP_IN'"
            (valueChange)="handleUP_CM_INChange($event)"
            (filterChange)="handleUP_CM_INFilter($event)">
</kendo-dropdownlist>

<kendo-dropdownlist *ngIf="selectedCS!='CM'" id="UP_CM_IN" name="UP_CM_IN"
            style="width:90%"
            [(ngModel)]="SelectUP_CM_IN"
            [defaultItem]="defaultUP_CM_IN"
            [data]="UP_CM_IN"
            [valueField]='CD_IN': 
            [textField]='UP_IN'"
            [filterable]="true"
            (valueChange)="handleUP_CM_INChange($event)"
            (filterChange)="handleUP_CM_INFilter($event)">
</kendo-dropdownlist>