我已将数据绑定到角度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"}]"
您的列表是一个对象数组,但您尝试将字符串设置为默认值使其错误,将默认值设置为您的列表项之一:
@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。