【问题标题】:How can't Type Array object list in TypeScript Angular2 [closed]如何在 TypeScript Angular2 中输入数组对象列表 [关闭]
【发布时间】:2017-06-30 11:17:08
【问题描述】:

option.ts

export class Option {
  id_cat: number;
  name_cat: string;
  image_cat: string;
  option_sub : {
    id_sub:  number;
    name_sub: string;
    icon_sub: string;
    ref_id_cat: number;
  }
}

enter image description here

在 Json 中

{"id_cat":4,
"name_cat":"Food",
"image_cat":"","option_sub":[{"id_sub":6,"name_sub":"American Food","icon_sub":"icon ion-pizza","ref_id_cat":4}]}

enter image description here

我想创建 MegaMenu

Angular2 中的 option_sub T_T 是什么类型

  option_sub :Array<{
    id_sub:  number;
    name_sub: string;
    icon_sub: string;
    ref_id_cat: number;
  }>;

【问题讨论】:

  • 请解释问题是什么或实际和预期的行为是什么。
  • 试着解释一下你的问题。
  • 对不起,我在模板中设置了错误的名称而不是 TS 中的错误

标签: angular typescript typescript-typings


【解决方案1】:

你可以创建另一个 Typescript 类:

export class Option {
  id_cat: number;
  name_cat: string;
  image_cat: string;
  option_sub : OptionSub[];
}

export class OptionSub {
    id_sub:  number;
    name_sub: string;
    icon_sub: string;
    ref_id_cat: number;
}

【讨论】:

    猜你喜欢
    • 2018-06-12
    • 2019-03-18
    • 1970-01-01
    • 2017-09-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 2021-07-19
    • 2017-09-06
    相关资源
    最近更新 更多