2013-02-01 194 views
-1

我有一个函数drawCountry试图读取基于点击的国家JSON文件:尝试捕捉404错误

d3.json("../json/"+d.id.toLowerCase()+"/regions.json", function(error, json) { 
     if (error) { 
      return console.warn(error); 
      self.drawMap(); 
     } 
     else { 
     self.regionsGroup.selectAll("path") 
     .data(json.features) 
     .enter().append("path") 
     .attr("d", self.projection) 
     .attr("id", function(d) { 
      return d.properties.name; 
     }) 
     .classed("country", true) 
     .attr("class", "country") 
     .on("mouseover", function(d) { 
      d3.select(this) 
      .style("fill", "#6C0") 
      .append("svg:title") 
      .text(d.properties.name); 
     }) 
     .on("mouseout", function(d) { 
      d3.select(this) 
      .style("fill", "#000000"); 
     }) 
     .on("click", function(d) { 
      console.log('clicked on country') 
     }); 
     } 
    }); 

我不能够看到如何加载self.drawMap();何时出现错误?

回答

0
return console.warn(error); <-- exits out of the function 
self.drawMap(); <--never gets called because of the return 

开关线

self.drawMap(); 
return console.warn(error);