剑道下拉的默认值未设置为角度

时间:2019-04-14 09:38:04

标签: angular kendo-ui

我已将数据绑定到angular 7应用程序中的kendo-下拉列表,现在尝试设置默认值。我已经将defaultItem属性设置为与valuefield相同的ID,但似乎没有显示默认值。而是显示文本FundClassId。

标记

fundclassSelected: any;

组件

"[{"FundClassId":13714,"FundClass":"Class D"},{"FundClassId":13717,"FundClass":"Class B"},{"FundClassId":13713,"FundClass":"Class A"},{"FundClassId":13716,"FundClass":"Class B1"},{"FundClassId":13715,"FundClass":"Class C"}]"

JSON结构

create-links-with puestos with [ not any? links]

1 个答案:

答案 0 :(得分:0)

您的列表是一个对象数组,但是您试图将字符串设置为默认值,这会使它出错,请像您的列表项之一一样设置默认值:

@Component({
  selector: 'my-app',
  template: `
    <kendo-dropdownlist 
    [data]="newData" 
    textField="FundClassId"
    valueField="FundClassId"
    [defaultItem]="defaultItem"
    >
    </kendo-dropdownlist>
  `
})
export class AppComponent {
  public newData = [{"FundClassId":13714,"FundClass":"Class D"},{"FundClassId":13717,"FundClass":"Class B"},{"FundClassId":13713,"FundClass":"Class A"},{"FundClassId":13716,"FundClass":"Class B1"},{"FundClassId":13715,"FundClass":"Class C"}];
  defaultItem = this.newData[0]; //or defaultItem = {"FundClassId":"default item ...","FundClass":"Class D"};
}

DEMO