Vis*_* KR 8 dictionary typescript es5-shim angular
我是typescript中的一只新蜜蜂,在我的angular4项目中,我收到了一个地图对象作为json。
所以我宣布了以下课程
<importing... required classes here..>
export class FormConfig {
public id: number;
public name: string;
public fieldMap :Map<string,Array<Field>>;
public fieldList : Array<Field> ;
}
Run Code Online (Sandbox Code Playgroud)
我从api收到完全相同的JSON。我对FormConfig的对象进行了控制台,并且正在获得没有任何错误的控制台。我的代码已编译,没有任何警告和错误。但是我无法通过使用Map的内置函数(例如forEach,keys,get等)从地图访问键和值。但是IDE显示了这些功能建议。我的部分代码如下。
formConfig : FormConfig;
console.log(JSON.stringify(formConfig)); // works fine
keys : string [] = Array.from (formConfig.keys()) ; // showing error (formConfig.keys is not a function)
Run Code Online (Sandbox Code Playgroud)
我正在为我的angular4项目使用es5目标,而IDE是Visual Studio代码。
在让我知道我在这里犯的错误之前,有人遇到过这个问题吗?
谢谢。
You can get the values using key like this:
for (const key in formConfig) {
console.log('The value for ' + key + ' is = ' + formConfig[key]);
}
Run Code Online (Sandbox Code Playgroud)
获取对象键值的数组是这样完成的:
keys: string [] = Object.keys(formConfig);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5786 次 |
| 最近记录: |