当我运行下面的代码时,jQuery重复地将一个Window对象放入我的数组中(我确信JSON不包含对Window对象的任何引用)。有没有办法运行它并保持Window对象不在我的数组中?
由于
$.getJSON("../php/return_network_data.php",
function(fetch_data){
$.each(fetch_data, function(){
var index = this.id;
node_array[index] = paper.circle(this.xpos_init, this.ypos_init, 10).attr({"fill" : "#ff0000"})
$.each(node_array, function(){
console.log(this);
});
});
}
);
答案 0 :(得分:0)
这应该有用..要在每个函数中添加索引,值
$.getJSON("../php/return_network_data.php",
function(fetch_data){
$.each(fetch_data, function(index,value){
var index2 = value.id;
node_array[index] = paper.circle(this.xpos_init, this.ypos_init, 10).attr({"fill" : "#ff0000"})
$.each(node_array, function(index,value){
console.log(value);
});
});
}
);
答案 1 :(得分:0)
我不确定paper.circle究竟做了什么(这是raphael?),但我认为这可能是两件事之一:
从paper命令中删除attr函数并稍后添加。
node_array[index] = paper.circle(this.xpos_init, this.ypos_init, 10);
为每个函数中的函数添加键值:
$.getJSON("../php/return_network_data.php", function(fetch_data){
$.each(fetch_data, function(key, value){
var index = value.id;
node_array[index] = paper.circle(value.xpos_init, value.ypos_init, 10).attr({"fill" : "#ff0000"})
$.each(node_array, function(){
console.log(this);
});
});
});
或者两者都可能?