作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
this.work[0].minValue = await this.getData().then(
value => value[0].set.min.X
)
this.work[1].minValue = await this.getData().then(
value => value[0].set.min.Y
)
this.work[2].minValue = await this.getData().then(
value => value[0].set.min.Z
)
this.work[3].minValue = await this.getData().then(
value => value[0].set.min.A
)
this.work[4].minValue = await this.getData().then(
value => value[0].set.min.B
)
this.work[5].minValue = await this.getData().then(
value => value[0].set.min.C
)
我试图在循环内编写这 6 行代码,但我无法做到。有人可以帮我吗?
var arr = ['X', 'Y', 'Z', 'A', 'B', 'C']
var i = 0
var that = this
this.work.forEach(item => {
item.minValue = that.getData().then(value => value[0].set.min.that.arr[i])
i++
})
我知道 min.that.arr[i] 这是错误的。请不要说出它不起作用的原因,请帮我解决问题。
最佳答案
value[0].set.min[arr[i]]
ashkan 的建议解决了我的问题。
关于javascript - 如何将变量 X 替换为数组索引 0 处的数据,其值为 'X',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59874071/
我是一名优秀的程序员,十分优秀!