繁体   English   中英

如何以角度访问动态对象

[英]how to access the dynamic object in angular

我的代码:

export class AppComponent implements OnInit {
 public manipulate: any ;
 ...
 this.results.forEach(result => {
   var index = result.date_value;
   if (!this.manipulate.hasOwnProperty(index)) {
     this.manipulate.{index} = [];
   }
   this.manupulate.{index}.push(result);
 });
}

预期结果:

this.manupulate = {
  20171001 : [
     0: { resultset },
     ...
  ]
}

如何编写程序。 如果我使用数组浏览器。 原因是索引值的范围较大。

下面的javascript代码可以完美运行。

manupulate[20171001] = 
  [
     0: { resultset },
     ...
  ]
}

如果我使用打字稿,浏览器就交给了。

this.manupulate[20171001] = 
  [
     0: { resultset },
     ...
  ]
}

谢谢大家

尝试这个 :

使用this.manupulate [index] .push(result); 而不是this.manupulate。{index} .push(result);

if (!this.manipulate.hasOwnProperty(index)) {
    this.manipulate[index] = [];
}
this.manupulate[index].push(result);

暂无
暂无

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

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