public counter = 0;
x0: any; x1: any; x2: any; x3: any; x4: any;
next(){
this.counter += 1;
this.storage.set("Count", this.counter);
console.log(this.counter);
this.logic();
}
logic(){
//automatic counter here
var xNum = JSON.parse(JSON.stringify("x" + this.counter));
xNum = true;
}
我有5个项目:X0-X5。 我想将它们设置为true,就像这样一个: this.X1 = true;
虽然我不想手动进行操作,但我希望分接计数器为我完成操作。 我该怎么办?
提前谢谢
答案 0 :(得分:0)
首先,您必须定义一个对象。
data = {
'x1': false,
'x2': false ...
}
for (let d in this.data) {
let str = 'x2' // let say you want to edit this one.
if (d === 'x2') {
this.data[d] = true;
}
}