嗨,我不明白为什么如果我在变量中写入 json 是正确的:
var theUI = {
"nodes":{"progetto 1":{"color":"red", "shape":"dot", "alpha":1},
"demos":{"color":"#b2b19d", shape:"dot", "alpha":1},
"halfviz":{"color":"#a7af00", "alpha":0, "link":""},
"atlas":{"color":"#a7af00", "alpha":0, "link":""},
"echolalia":{"color":"#a7af00", "alpha":0, "link":""},
"docs":{"color":"#b2b19d", "shape":"dot", "alpha":1},
"reference":{"color":"#922E00", "alpha":0, "link":""},
"introduction":{"color":"#922E00", "alpha":0, "link":""},
"code":{"color":"#b2b19d", "shape":"dot", "alpha":1},
"github":{"color":"orange", "alpha":0, "link":""},
".zip":{"color":"orange", "alpha":0, "link":""},
".tar.gz":{"color":"orange", "alpha":0, "link":""}
},
"edges":{
"progetto 1":{
"demos":{"length":.8},
"docs":{"length":.8},
"code":{"length":.8}
},
"demos":{"halfviz":{},
"atlas":{},
"echolalia":{}
},
"docs":{"reference":{},
"introduction":{}
},
"code":{".zip":{},
".tar.gz":{},
"github":{}
}
}
}
var sys = arbor.ParticleSystem()
sys.parameters({stiffness:900, repulsion:2000, gravity:true, dt:0.015})
sys.renderer = Renderer("#sitemap")
sys.graft(theUI)
var nav = Nav("#nav")
$(sys.renderer).bind('navigate', nav.navigate)
$(nav).bind('mode', sys.renderer.switchMode)
nav.init()
})
而如果我从文件 json 中提供数据,则程序不起作用:
var theUI = $.getJSON("data.json")
var sys = arbor.ParticleSystem()
sys.parameters({stiffness:900, repulsion:2000, gravity:true, dt:0.015})
sys.renderer = Renderer("#sitemap")
sys.graft(theUI)
var nav = Nav("#nav")
$(sys.renderer).bind('navigate', nav.navigate)
$(nav).bind('mode', sys.renderer.switchMode)
nav.init()
})
它执行获取并读取 json,但程序不起作用。
文件 data.json 是这样的:
{
"nodes":{"progetto 1":{"color":"red", "shape":"dot", "alpha":1},
"demos":{"color":"#b2b19d", shape:"dot", "alpha":1},
"halfviz":{"color":"#a7af00", "alpha":0, "link":""},
"atlas":{"color":"#a7af00", "alpha":0, "link":""},
"echolalia":{"color":"#a7af00", "alpha":0, "link":""},
"docs":{"color":"#b2b19d", "shape":"dot", "alpha":1},
"reference":{"color":"#922E00", "alpha":0, "link":""},
"introduction":{"color":"#922E00", "alpha":0, "link":""},
"code":{"color":"#b2b19d", "shape":"dot", "alpha":1},
"github":{"color":"orange", "alpha":0, "link":""},
".zip":{"color":"orange", "alpha":0, "link":""},
".tar.gz":{"color":"orange", "alpha":0, "link":""}
},
"edges":{
"progetto 1":{
"demos":{"length":.8},
"docs":{"length":.8},
"code":{"length":.8}
},
"demos":{"halfviz":{},
"atlas":{},
"echolalia":{}
},
"docs":{"reference":{},
"introduction":{}
},
"code":{".zip":{},
".tar.gz":{},
"github":{}
}
}
}