在某些(并非全部)浏览器中,在D3 JavaScript中读取JSON文件时出现问题 [英] Problems reading JSON file in D3 javascript in some (not all) browsers
问题描述
我在读取JSON文件后立即在Chrome中收到此错误.它可以在Safari和Firefox中正常工作.
I get this error in Chrome immediately after reading a JSON file. It works correctly in Safari and Firefox.
console.log(事件->" +"postcards.nodes [0] .node.event");//在Chrome浏览器中"tally""TypeError:无法读取未定义的属性'node'".<
console.log ("event -> "+ postcards.nodes[0].node.event); // "tally" in Safari "TypeError: Cannot read property 'node' of undefined" in Chrome.<
嵌套JSON文件中的级别是否有限制?我从Drupal视图生成JSON.这是开始:
Is there a limit to the levels in a nested JSON file? I generate the JSON from a Drupal view. Here here is the start:
{"nodes":[{"node":{"w1":"","w2":"1","w3":"","w4":"", ...<
这是Javascript:
Here is the Javascript:
d3.json(
"/sites/default/d3_files/json/toronto-wards.json",
function(error,wards) {
d3.json("/postcards-json", function(error, postcards) {
console.log ("event -> "+ postcards.nodes[0].node.event); // tally in Safari
我使用的是macOS,而我的使用Windows的朋友在Firefox中也遇到相同的错误.
I'm using macOS and my friends using Windows get the same error in Firefox.
根据请求,我认为这是XHR消息:
As per request here is what I think is the XHR message:
d3.min.js:1 XHR finished loading: GET "http://www.stopplastics.ca/postcards-json".
推荐答案
该问题是由于未正确创建Drupal视图引起的.与Chrome浏览器无关.
The problem was caused by the Drupal view not being created correctly. Nothing to do with the Chrome browser.
这篇关于在某些(并非全部)浏览器中,在D3 JavaScript中读取JSON文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!