用对象数组填充文本和值的数组

时间:2019-06-03 10:50:09

标签: angular

我试图用角对象数组填充文本和值的数组。我已经共享了包含对象数组的JSOn。

声明

public AuditYearEnd: Array<{ text: string, value: number }>;

分配-我如何在这里分配。

this.AuditYearEnd = this._fundTerms.AuditYearEndMonths;

JSON:

[
  {
    "Text": "31 January",
    "Value": "1",
    "Selected": false
  },
  {
    "Text": "28 February",
    "Value": "2",
    "Selected": false
  },
  {
    "Text": "31 March",
    "Value": "3",
    "Selected": false
  },
  {
    "Text": "30 April",
    "Value": "4",
    "Selected": false
  },
  {
    "Text": "31 May",
    "Value": "5",
    "Selected": false
  },
  {
    "Text": "30 June",
    "Value": "6",
    "Selected": false
  },
  {
    "Text": "31 July",
    "Value": "7",
    "Selected": false
  },
  {
    "Text": "31 August",
    "Value": "8",
    "Selected": false
  },
  {
    "Text": "30 September",
    "Value": "9",
    "Selected": false
  },
  {
    "Text": "31 October",
    "Value": "10",
    "Selected": false
  },
  {
    "Text": "30 November",
    "Value": "11",
    "Selected": false
  },
  {
    "Text": "31 December",
    "Value": "12",
    "Selected": false
  }
]

标记

   <kendo-dropdownlist *ngIf="EditMode" style="width:100%" class="form-control form-control-sm"  [(ngModel)]="auditYearEndSelected"
          data="AuditYearEnd"  [filterable]="false" textField="Text" [valuePrimitive]="true" valueField="Value">
      </kendo-dropdownlist>

组件代码

get FundTerms(): any {
        return this._fundTerms;
    }

     @Input('FundTerms')
    set FundTerms(value: any) {
        this._fundTerms = value;
        if (this._fundTerms) {
         this.Fund = this._fundTerms.FundTermsDetailViewModel[0];
         this.AuditYearEnd = this._fundTerms.AuditYearEndMonths;
         this.isAgreement = this._fundTerms.FundTermsDetailViewModel[0].SideLetterAgreement;
        }
    }

1 个答案:

答案 0 :(得分:0)

您犯了一个愚蠢的错误。您会忘记数据属性的方括号。


// put the square bracket for data attribute.
    <kendo-dropdownlist *ngIf="EditMode" 
                        style="width:100%" 
                        class="form-control form-control-sm"  
                        [(ngModel)]="auditYearEndSelected"
                        [data]="AuditYearEnd"
                        [filterable]="false" textField="Text" 
                        [valuePrimitive]="true"
                        valueField="Value">
    </kendo-dropdownlist>