Class 成员变量是动态的。取决于打字稿中地图的键
Class member variable are dynamic. Depending upon the keys of a map in typescript
我有一张打字稿地图
myMap : Map = new Map();
myMap 有一些键和值
我正在像下面这样迭代地图
for(let [key, value] of this.myMap) {
///some code which can create a class whose member variable will be the key of the map and the values of the member variables will be the values of the keys
}
例如,如果地图的键是 ==> 苹果、芒果等
如果相应的值为 1、2
然后在迭代地图时动态创建
myClass {
apple = 1;
mango = 2;
}
你能试试这个吗
let myClass = {};
for (const [key, value] of this.myMap.entries()) {
myClass = {
...myClass,
[key]: value,
}
}
我有一张打字稿地图 myMap : Map = new Map();
myMap 有一些键和值
我正在像下面这样迭代地图
for(let [key, value] of this.myMap) {
///some code which can create a class whose member variable will be the key of the map and the values of the member variables will be the values of the keys
}
例如,如果地图的键是 ==> 苹果、芒果等 如果相应的值为 1、2 然后在迭代地图时动态创建
myClass {
apple = 1;
mango = 2;
}
你能试试这个吗
let myClass = {};
for (const [key, value] of this.myMap.entries()) {
myClass = {
...myClass,
[key]: value,
}
}