【发布时间】:2018-10-26 12:04:17
【问题描述】:
[
{
"day": 0,
"periods": [
{
"start": "01:00",
"end": "02:00",
"title": "",
"backgroundColor": "rgba(254, 0, 0, 0.7)",
"borderColor": "rgb(42, 60, 255)",
"textColor": "rgb(0, 0, 0)"
},
{
"start": "02:30",
"end": "03:00",
"title": "",
"backgroundColor": "rgba(254, 0, 0, 0.7)",
"borderColor": "rgb(42, 60, 255)",
"textColor": "rgb(0, 0, 0)"
}
]
},
{
"day": 1,
"periods": [
{
"start": "01:00",
"end": "02:00",
"title": "",
"backgroundColor": "rgba(254, 0, 0, 0.7)",
"borderColor": "rgb(42, 60, 255)",
"textColor": "rgb(0, 0, 0)"
}
]
},
{
"day": 2,
"periods": [
{
"start": "01:00",
"end": "01:30",
"title": "",
"backgroundColor": "rgba(254, 0, 0, 0.7)",
"borderColor": "rgb(42, 60, 255)",
"textColor": "rgb(0, 0, 0)"
}
]
},
{
"day": 3,
"periods": [
{
"start": "02:00",
"end": "02:30",
"title": "",
"backgroundColor": "rgba(254, 0, 0, 0.7)",
"borderColor": "rgb(42, 60, 255)",
"textColor": "rgb(0, 0, 0)"
}
]
},
{
"day": 4,
"periods": [
{
"start": "01:00",
"end": "01:30",
"title": "",
"backgroundColor": "rgba(254, 0, 0, 0.7)",
"borderColor": "rgb(42, 60, 255)",
"textColor": "rgb(0, 0, 0)"
}
]
},
{
"day": 5,
"periods": [
{
"start": "01:30",
"end": "02:00",
"title": "",
"backgroundColor": "rgba(254, 0, 0, 0.7)",
"borderColor": "rgb(42, 60, 255)",
"textColor": "rgb(0, 0, 0)"
},
{
"start": "03:00",
"end": "03:30",
"title": "",
"backgroundColor": "rgba(254, 0, 0, 0.7)",
"borderColor": "rgb(42, 60, 255)",
"textColor": "rgb(0, 0, 0)"
}
]
},
{
"day": 6,
"periods": []
}
]
如何在Javascript中用动态变量制作这样的数据结构? 让我们说: 我需要在 day:6 或 day:2 中更改 period[start] 和 period[end] 时间 我想制作像数据一样的新 data2 结构,但要使用我的时间变量。 像这样:
for (var i=0; i <arr.legth; ++i){
data2="'[{"day":MYVARIABLE1,"periods":[{"start":"MYVARIABLE2","end":"MYVARIABLE3", ...}]';
}
【问题讨论】:
-
你希望通过这个实现什么目标?
-
我认为您正在尝试创建对象,然后您必须将它们附加到主数组。但是你到底想达到什么目的呢?
-
我想更改 period[start]="01:00"] where day=2
-
解析它,然后循环遍历它并找到您需要更改的内容?或者只是解析它并设置你的变量?除非你给我们一些背景信息,否则有 1000 种方法可以做到这一点。
-
@Ele: 如果
data2是一个字符串,则不是...
标签: javascript