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

问题描述 投票:1回答:1

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

标记

 valueField="FundClassId" defaultItem = "FundClassId"  (valueChange)="flashClassChanged($event)"></kendo-dropdownlist>

零件

fundclassSelected: any;

JSON结构

"[{"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"}]"
angular kendo-ui
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.