繁体   English   中英

类型上不存在属性“cat”

[英]Property 'cat' does not exist on type

我有一个问题,在下面的代码部分:

getPorts() {
let brands = [];

this.vehicles.forEach(country => {
  country.brands.forEach(brand => {
    brand.cat = country ;
    brands.push(brand);
  });
});
console.log(brands);
this.brands = brands;
} 

错误是:

Property 'cat' does not exist on type '{ 'brand': string; 'flag': string; }'.

如何解决这个问题。

她是我使用的一部分数据:

{
  'cat': 'A',
  'brands': [
    {
      'brand': 'Adamoli','flag':'https://restcountries.eu/data/ita.svg'
    },

  ]
},

也许其中一个品牌没有属性“猫”。

如果没有看到您的数据模型,很难回答这个问题。 你能通过 console.log 退出“this.vehicles”吗?

看起来数据部分是“国家”,其中包含“猫”。 但是您试图从不包含该属性的“品牌”中获取“猫”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM