问题
I'm trying to using queues to ensure my files are loaded fully before the script continues. However, when I load in my json map files and try to use them in a function, I get an error.
var counties = svg.append("g")
.attr("id", "counties")
.attr("class", "Blues");
var states = svg.append("g")
.attr("id", "states");
queue()
.defer(d3.json, "county.json")
.defer(d3.json, "state.json")
.defer(d3.json, "Crashes.json")
.await(ready);
function ready(county, state, crashes) {
var countyFeatures = topojson.feature(county, county.objects.counties);
var stateFeatures = topojson.feature(state, state.objects.states);
/*
counties.selectAll("path")
.data(county.features)
.enter().append("path")
.attr("class", "q8-9")
.attr("d", path);
states.selectAll("path")
.data(state.features)
.enter().append("path")
.attr("d", path);
*/
}
The error is Uncaught TypeError: Cannot read property 'objects' of null
Can someone explain why when passing into the function it is null? As opposed to running d3.json separately and using
d3.json("URL", function(d) {var temp = topojson.feature(d, d.objects.counties;});
Thanks.
来源:https://stackoverflow.com/questions/22247330/queue-error-uncaught-typeerror-cannot-read-property-objects-of-null