【发布时间】:2017-02-17 09:01:06
【问题描述】:
我正在尝试使用 Kendo UI 创建一个下拉列表,除了在屏幕加载时有一个默认的 selected 值之外,它工作得很好。
根据他们的documentation,我的代码应该是这样的:
HTML:
<kendo-dropdownlist formControlName="description"
[data]="definitionData.Languages"
[(ngModel)]="languageValue"
[textField]="'Value'"
[valueField]="'Key'"
[value]="2"
[valuePrimitive]="true">
</kendo-dropdownlist>
<span class="left col-xs-6">
<input type="text" id="descriptionField" class="form-control" [value]="getValue(descriptionForm.controls.description.value)" #descriptionField (blur)="updateDescriptionValue(descriptionField.value, languageValue)" />
</span>
组件:
public descriptionForm: FormGroup = new FormGroup({
description: new FormControl()
});
我的下拉菜单有效,但加载页面时默认选择的值为空白,它应该是带有Key: 2的对象
注意:我不想使用[defaultItem],因为它只会复制该项目,这意味着它将在下拉列表中出现 2 次。
我尝试了很多东西,但我不知道我应该做什么!
提前致谢
【问题讨论】:
-
为什么要同时使用
ngModel和value?确保value是data的元素 -
@KonradKahl 因为我的表单需要是响应式的,并且根据他们使用
value设置默认选定值的文档(我希望它是Key = 2所在的项目,这也会发生成为数组中的第二项
标签: javascript angular drop-down-menu kendo-ui