【发布时间】:2015-12-02 19:35:48
【问题描述】:
我正在使用 d3.js 图表,它所依赖的数据如下所示:
var graph = {
"nodes" : [{"name" : "Appointments"},{"name" : "Store Visit"},{"name" : "Visit History"},{"name" : "Resume Store Visit"}],
"links" : [{"source":"Store Visit","target":"Appointments","value":6},
{"source":"Appointments","target":"Visit History","value":7},
{"source":"Visit History","target":"Store Visit","value":2},
{"source":"Resume Store Visit","target":"Visit History","value":1},
{"source":"Appointments","target":"Resume Store Visit","value":5}]
};
我的 REST 服务返回完全相同的数据,但属性名称是 Source、Target 和 Value(注意首字母大写)
这会出错
Uncaught TypeError: Cannot read property 'weight' of undefinedl.start @ d3.v3.min.js:4(anonymous function) @ userflowd3.html:64(anonymous function) @ d3.v3.min.js:1t @ d3.v3.min.js:1u @ d3.v3.min.js:1
那么,json 返回 data.items 将属性值替换为小写的方式是什么?
【问题讨论】:
标签: javascript d3.js graph