Kendo DropDownList,嵌套对象为TextField

时间:2019-09-17 16:03:36

标签: angular kendo-ui telerik

我有一个kendo-dropdownlist,想将textField属性分配给位于嵌套对象内的属性。

用户对象:

{ 
  id: 123456  <--valueField
  contact: {
      name: Jane Doe <--textField
      email: 
      ...
  }
}

问题在于Kendo不会在所选框中或下拉菜单中显示姓名,因为它似乎无法在contact对象中找到contact.name属性或任何其他属性。

这是我的配置方式,并假设它是因为网格的 kendo-grid-column field属性可以使用嵌套对象属性名称:

<kendo-dropdownlist id="profileOwner"
                    [data]="userData"
                    [textField]="'contact.name'"
                    [valueField]="'id'"
                    [(ngModel)]="profileOwner"
                    [valuePrimitive]="true"></kendo-dropdownlist>

我知道Kendo可以找到对象,因为当我将文本字段设置为[textField]="'contact'"时,它会显示以下内容: Object,Object

我尝试了各种配置:

<kendo-dropdownlist id="profileOwner"
                    [data]="userData"
                    [textField]="contact.name"  <-- Cannot find object error 
                    [valueField]="'id'"
                    [(ngModel)]="profileOwner"
                    [valuePrimitive]="true"></kendo-dropdownlist>
---
<kendo-dropdownlist id="profileOwner"
                    [data]="userData"
                    textField="contact.name"  <-- I still get Nothing
                    valueField="id"
                    [(ngModel)]="profileOwner"
                    [valuePrimitive]="true"></kendo-dropdownlist>

发布此帖子之前,我打算采取的解决方法是使用项目模板显示值。这将成功在下拉窗口中显示值,但不会在所选框中显示这些值:

<kendo-dropdownlist id="profileOwner"
                    [data]="userData"
                    [textField]="'contact.name'"
                    [valueField]="'id'"
                    [(ngModel)]="profileOwner"
                    [valuePrimitive]="true">
         <ng-template kendoDropDownListItemTemplate let-dataItem>
                <span class="template">{{ dataItem.contact.name }}</span>
         </ng-template>
</kendo-dropdownlist>

Workaround attempt

版本信息:

Angular: 7.2.9
@progress/kendo-angular-dropdowns: ^3.5.0

1 个答案:

答案 0 :(得分:0)

简单。只需如下更改代码:

<kendo-dropdownlist id="profileOwner"
                    [data]="userData"
                    [textField]="contact.name"
                    [valueField]="id"
                    [(ngModel)]="profileOwner"
                    [valuePrimitive]="true"></kendo-dropdownlist>

这是因为为什么要绑定例如ID行[valueField]="id"而不是字符串[valueField]="'id'"