【发布时间】:2014-01-08 21:52:00
【问题描述】:
我被困住了...
我想使用嵌套数组中字段的数据。我是新手,所以我错过了一些部分:-(
如果在调试d[0].children[1].birthdate 中写入,我会得到正确的值。当我尝试绘制我的日期时,我只能从我的“父母”数据中获得第一个孩子。
//Part of my code:
circle.append("circle")
.style("fill", "purple")
.attr("r", 5)
//This get me each parent first child but I need all the children e.g Adam, Eve, Julia....
.attr("cx", function(d,i,j) { return x(new Date(d.parent[j].birthdate));})
我的数据:
"parent":[
"name": "Mum",
"children": [
{
"name": "Adam",
"birthdate": "2013-01-05"
},
{
"name": "Eve",
"birthdate": "2013-02-05"
},
{
"name": "Julia",
"birthdate": "2013-03-05"
}
]
},
{
"name": "Dad",
"children": [
{
"name": "Romeo",
"birthdate": "2013-04-05"
},
{
"name": "Maria",
"birthdate": "2013-03-15"
}
]
},
"name": "StepMom",
"children": [
{
"name": "A",
"birthdate": "2013-01-05"
},
{
"name": "B",
"birthdate": "2013-02-05"
},
{
"name": "C",
"birthdate": "2013-03-05"
}
]
}
]
【问题讨论】:
标签: javascript arrays d3.js nested