2017-07-15 21 views
1

基本上我試圖創建一個gui,以便於文件編輯。無法讀取未定義的屬性「日期」

我有一個這樣的數組:(鍵是動態的,所以數組不使用模板,我可以參考它的內容。)

console.log output here for the array

當我通過努力環它給了我一個錯誤:

Cannot read property 'date' of undefined

在此行發生在multiarray.component.html錯誤:

<ng-template [ngIf]="getType(configFile[key][sub]) === 'multiarray'"> 
    <multiarray-component [key]="sub" [configFile]="configFile" [value]="configFile[key][sub]" [descriptions]=""></multiarray-component> 
</ng-template> 

代碼: multiarray.component.html

<div class="col-md-12"> 
    <h4>{{key}}</h4> 

    <div class="row"> 

    <ng-template [ngIf]="getType(value) !== 'multiarray'"> 
     <ng-template [ngIf]="getType(configFile[key]) === 'text' || getType(configFile[key]) === 'number'"> 
     <input-component [key]="key" [value]="configFile[key]" [descriptions]=""></input-component> 
     </ng-template> 

     <ng-template [ngIf]="getType(configFile[key]) === 'boolean'"> 
     <checkbox-component [key]="key" [value]="configFile[key]" [descriptions]=""></checkbox-component> 
     </ng-template> 

     <ng-template [ngIf]="getType(configFile[key]) === 'array'"> 
     <array-component [key]="key" [value]="configFile[key]" [descriptions]=""></array-component> 
     </ng-template> 
    </ng-template> 

    <ng-template [ngIf]="getType(value) === 'multiarray'"> 
     <div *ngFor="let sub of getKeys(value)"> 

     <ng-template [ngIf]="getType(configFile[key][sub]) === 'multiarray'"> 
      <multiarray-component [key]="sub" [configFile]="configFile" [value]="configFile[key][sub]" [descriptions]=""></multiarray-component> 
     </ng-template> 

     <ng-template [ngIf]="getType(configFile[key][sub]) === 'text' || getType(configFile[key][sub]) === 'number'"> 
      <input-component [key]="sub" [value]="configFile[key][sub]" [descriptions]=""></input-component> 
     </ng-template> 

     <ng-template [ngIf]="getType(configFile[key][sub]) === 'boolean'"> 
      <checkbox-component [key]="sub" [value]="configFile[key][sub]" [descriptions]=""></checkbox-component> 
     </ng-template> 

     <ng-template [ngIf]="getType(configFile[key][sub]) === 'array'"> 
      <array-component [key]="sub" [value]="configFile[key][sub]" [descriptions]=""></array-component> 
     </ng-template> 
     </div> 
    </ng-template> 
    </div> 

    <span *ngFor="let description of descriptions">{{description}}</span> 
</div> 

multiarray.component.ts

import {Component, Input} from "@angular/core"; 

@Component({ 
    selector: 'multiarray-component', 
    templateUrl: './multiarray.component.html', 
    styles: [` 
    span { 
     display: block; 
     font-size: 11px; 
    } 
    `], 
}) 
export class MultiArrayComponent { 
    @Input() key: string; 
    @Input() value: object; 
    @Input() configFile: object; 
    @Input() descriptions: string[]; 

    getType(obj): string { 
    let type = Object.prototype.toString.call(obj); 
    switch (type) { 
     case "[object String]": { 
     return "text"; 
     } 
     case "[object Number]": { 
     return "number"; 
     } 
     case "[object Boolean]": { 
     return "boolean"; 
     } 
     case "[object Array]": { 
     return "array"; 
     } 
     case "[object Null]": { 
     return "null"; 
     } 
     case "[object Object]": { 
     return "multiarray"; 
     } 
     default: 
     return "unknown"; 
    } 
    } 

    getKeys(object: object): string[] { 
    return Object.keys(object); 
    } 
} 

有人能解釋我做錯了嗎?謝謝。

回答

0

固定。 問題是,我試圖從CONFIGFILE [關鍵] [副]的代替值[子]獲得數據

相關問題