这个网站我在这里进行分段:http://graysonearle.com/hosted/signified/有一个问题:当它加载时,应该在三角形的一些随机交点处出现(其中五个)红点。但是,似乎事情没有以正确的顺序加载,所以我留下了这个不能读取属性错误。
在执行' addPerson'之前,如何确保JSON对象和草图元素都已加载?功能?错误:"未捕获的TypeError:无法读取属性' addPerson'未定义"
var p; // sketch id
// see if sketch canvas has loaded before doing anything
var checkExist = setInterval(function() {
if ($('#sketch').length) {
clearInterval(checkExist);
p = Processing.getInstanceById('sketch');
$.getJSON("data.json", function(data) {
// load in JSON data to processing sketch
for (var i = 0; i < data.length; i++) {
p.addPerson(data[i]);
}
}).done(function() {
// callback
});
}
}, 100); // check again if not loaded...
和addPerson代码:
function addPerson(var json) {
// get random coordinate from the stack
int rando = floor(random(intersections.size()));
PVector pv = (PVector) intersections.get(rando);
// add new node with coordinate and json data fed from index.html js call
nodes.add(new Node(pv, json.Name, json.Location, json.Details, json.PhotoURL, json.Vimeo));
// delete coord after using!
intersections.remove(rando); // bye bye! no two nodes should have same loc
}