角剑道下拉列表错误data.map不是函数

时间:2019-04-11 09:17:06

标签: angular kendo-ui

我在angular 7应用程序中加入了Kendo下拉列表。我正在尝试将对象FundClass绑定到下拉列表。我将FundClass对象从父组件传递到子组件,并将该数据绑定到子组件中的下拉列表。数据确实绑定了,并且可以在下拉控件中看到数据,但是当我选择一个下拉项时, 我收到以下错误

data.map is not a function
    at DropDownListComponent.push../node_modules/@progress/kendo-angular-dropdowns/dist/es/dropdownlist.component.js.DropDownListComponent.findDataItem (dropdownlist.component.js:949) 

我要绑定的数据的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"}]"

父组件

此处的数据对象包含FundClass对象。

getManagerStrategyFunds() {
        this.strategyService.getManagerStrategyFunds(this.ManagerStrategyId, this.ValueDate)
            .subscribe((data: any) => {
                this.ViewModel = data;
               this.GridOptions.rowData = data.SummaryPerformance;
               this.FundPerformance = data.SummaryPerformance;
            },
            err => {
                this.Error = 'An error has occurred. Please contact BSG';
            },
            () => {
            });
    }

父组件html。传递对象ftr.FundClass

 <div class="panel panel-default">
        <div class="panel-heading product-heading">
            <span style="font-size: 14px; font-weight: bold;">Performance Track Record and Statistics</span>
        </div>
        <div  *ngIf ="ViewModel.FundPerformance">
            <div class="panel-body" style="width:100%">
                <div *ngFor="let ftr of ViewModel.FundPerformance">
                    <fund-statistics [fundStatistics]="ftr.FundStatistics"  [fundTrackRecord]= "ftr.TrackRecord" [fundName]="ftr.FundName" 
                                     [benchMark1Name]="ftr.BenchmarkName1" [benchMark2Name]="ftr.BenchmarkName2" [fundclass]="ftr.FundClass" ></fund-statistics>
                </div>
            </div>
        </div>   
    </div>  

子组件

@Input() fundclass: any;

    flashClassChanged(e) {

    }

Child compoenent html

 <kendo-dropdownlist style="width:170px" [data]="fundclass" [filterable]="false"
            [(ngModel)]="fundclass" textField="FundClass" (valueChange)="flashClassChanged($event)"
            valueField="FundClassId"></kendo-dropdownlist>  

1 个答案:

答案 0 :(得分:0)

问题出在模型绑定时,您在绑定(用于数据)时对元素使用相同的属性。否则将其更改为其他值,当您更改值时,所选值将设置为fundclass属性值,但下拉数据应为数组。在插件中,他们期望一个数组,而map函数仅适用于数组,但是当您选择一个更新为对象的值数据值时。

模板:

<kendo-dropdownlist style="width:170px" [data]="fundclass" [filterable]="false"
        [(ngModel)]="fundclassSelected" textField="FundClass" (valueChange)="flashClassChanged($event)"
        valueField="FundClassId"></kendo-dropdownlist> 

TS:

@Input() fundclass: any;

fundclassSelected:any;

flashClassChanged(e) {

}