我正在使用D3js与Mongodb和AnguarlJS来显示我的数据。所有这一切都很好,直到我给我的JSON数组命名为止。然后角开始抱怨的东西,我不知道为什么。未捕获TypeError:undefined不是使用名称为JSON对象时的函数
这是原来的JSON数组,这个原代码工作
[
{
"defaultCategory":"Happy",
"timesUsed":2704659
},
{
"defaultCategory":"Sad",
"timesUsed":4499890
},
{
"defaultCategory":"Laughter",
"timesUsed":2159981
},
{
"defaultCategory":"Smirk",
"timesUsed":3853788
},
{
"defaultCategory":"Flirty",
"timesUsed":14106543
}
]
d3.json("data.json", function(error, data) {
data.forEach(function(d) {
d.timesUsed =+ d.timesUsed;
});
但是当我的JSON改变这种格式,它打破
{
"mymood":[
{
"defaultCategory":"Happy",
"timesUsed":2704659
},
{
"defaultCategory":"Sad",
"timesUsed":4499890
},
{
"defaultCategory":"Laughter",
"timesUsed":2159981
},
{
"defaultCategory":"Smirk",
"timesUsed":3853788
},
{
"defaultCategory":"Flirty",
"timesUsed":14106543
}
]
}
d3.json("data.json", function(error, data) {
data.mymood.forEach(function(d) {
d.timesUsed =+ d.timesUsed;
});
在Chrome控制台中的错误发生在线data.mymood.foreach线, ,但我不明白为什么,因为它完全返回相同的JSON,就好像没有这样的名字
[对象,对象,对象,对象,对象]
和在该函数的参数d也返回数组
编辑
误差内相同的对象:
遗漏的类型错误:undefined不是函数
console.log(data) - > Object {mymood:Array [5]}
的console.log(data.mymood) - > [对象,对象,对象,目标,对象]
要点对于那些有兴趣谁在全码
https://gist.github.com/gwong89/e3a29b64d94ad20256bb
当你'console.log(data)'或'console.log(data.mymood)'什么出来? – 2015-02-11 19:33:54
你得到的错误是什么? – 2015-02-11 19:34:06
检查编辑上面,我刚刚添加 – 2015-02-11 19:40:16