从配置问题读取的多个 FOR var 循环
Multiple FOR var loops that read from config Issue
我正在设置我的代码但遇到了问题..
这段代码只是我正在尝试做的一个例子。
所以基本上 config.Te[i].ref 应该读取 Te.. 中的所有 ref.. 但它只读取第一行而不是 Te..
中的所有行
问候
for (var i in config.acc,config.Te,config.Hu,config.Ve)
console.log(config.Te[i].ref)
{}
当我将日志输出更改为 config.acc[i].ref 或其他时,它也只读取该特定配置的第一行。
但是当我将其更改为 for (var i in config.acc) 时,它会读取所有参考...
所以我想我的代码格式有误,而且我不知道如何修复它。
错误必须在于分离配置。
我只想一个一个地称呼它们。
"acc":
[
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 }
],
您可以将主要对象存储在数组中,然后使用嵌套 for 循环。
const arr = [config.acc,config.Te,config.Hu,config.Ve]
for(let elm of arr){
for(let i in elm){
console.log(elm[i].ref)
}
}
我正在设置我的代码但遇到了问题.. 这段代码只是我正在尝试做的一个例子。 所以基本上 config.Te[i].ref 应该读取 Te.. 中的所有 ref.. 但它只读取第一行而不是 Te..
中的所有行问候
for (var i in config.acc,config.Te,config.Hu,config.Ve)
console.log(config.Te[i].ref)
{}
当我将日志输出更改为 config.acc[i].ref 或其他时,它也只读取该特定配置的第一行。
但是当我将其更改为 for (var i in config.acc) 时,它会读取所有参考...
所以我想我的代码格式有误,而且我不知道如何修复它。 错误必须在于分离配置。 我只想一个一个地称呼它们。
"acc":
[
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 },
{"type":"PIR", "ref":0 }
],
您可以将主要对象存储在数组中,然后使用嵌套 for 循环。
const arr = [config.acc,config.Te,config.Hu,config.Ve]
for(let elm of arr){
for(let i in elm){
console.log(elm[i].ref)
}
}