javascript - 在javascript中循环数据
问题描述
我正在尝试在图表中显示数据。我从我的控制器传递的数据如下。
0: {label: "500", backgroundColor: "rgb(102,205,170,0.5)", borderColor: "rgb(102,205,170,0.5)", data: "13,49,2,2"}
1: {label: "1000", backgroundColor: "rgb(0,191,255,0.5)", borderColor: "rgb(0,191,255,0.5)", data: "40,2,41,4"}
2: {label: "1500", backgroundColor: "rgb(112,128,144,0.5)", borderColor: "rgb(112,128,144,0.5)", data: "3,41,0,8"}
3: {label: "2000", backgroundColor: "rgb(220,20,60,0.5)", borderColor: "rgb(220,20,60,0.5)", data: "28,30,40,43"}
4: {label: "2500", backgroundColor: "rgb(240,230,140,0.5)", borderColor: "rgb(240,230,140,0.5)", data: "0,6,20,14"}
5: {label: "3000", backgroundColor: "rgb(0,191,255,0.5)", borderColor: "rgb(0,191,255,0.5)", data: "31,26,31,32"}
现在我想遍历数据所以结果就像
label: '500',
backgroundColor: rgb(102,205,170,0.5),
borderColor: rgb(102,205,170,0.5),
data: [
26,2,41,13
],
...
我尝试过的如下
for (const [key, value] of Object.entries(dataChart)) {
console.log(key.borderColor);
}
在这里我只是想显示borderColor,但它说'未定义'
任何帮助将不胜感激。
解决方案
你需要做的是value.borderColor
而不是key.borderColor
推荐阅读
- npm - NPM 更新失败,出现错误 1 和退出代码 2
- java - FizzBuzz 使用有限数量的条件和 StringBuilder
- python - Python 无法从同一个包中的模块导入函数
- ios - 是否可以影响 AppStore 中呈现的“开发者形象”?
- jenkins - 如何在发布分支下创建标签?
- c++ - Win32 API C++ Hwnd 返回 Null
- wpf - 为什么我不能在 wpf 的资源字典中使用我的静态资源?
- c++ - 如何将 cc_binary 转换为 cc_library?
- python - Python - 从外部命令退出脚本
- algorithm - 子图选择算法问题(动态规划或 NP)