")而不是 ":"-6ren"> ")而不是 ":"-我想在 Jekyll 草案中使用 d3.js 制作一个 Chopleth。 但不知何故 Jekyll 正在更改我的 JSON 文件 {"type":"FeatureCollection", "feat-6ren">
gpt4 book ai didi

javascript - Jekyll 破坏 JSON 文件。箭头 ("=>")而不是 ":"

转载 作者:行者123 更新时间:2023-11-28 04:16:37 24 4
gpt4 key购买 nike

我想在 Jekyll 草案中使用 d3.js 制作一个 Chopleth。

但不知何故 Jekyll 正在更改我的 JSON 文件

{"type":"FeatureCollection", "features":[{"type":"Feature", "id":"01",

{"type"=>"FeatureCollection", "features"=>[{"type"=>"Feature", "id"=>"01",

我希望 jekyll 将我的 json 文件放入 d3.json() 函数中,如下所示:

d3.json({{site.data.us-states}},  function(json){
svg.selectAll("path") blah blah

其中 us-states 是我的 us-states.json 文件,但 Jekyll 却把它放在各处 =>

有人可以帮助我吗?

最佳答案

网站Jekyll global variable .

site.data 是一个 Ruby 哈希,包含从位于 _data 目录中的 YAML 文件加载的数据。

我认为

site.data.us-states 是一个 Ruby 哈希或数组。

d3.json is a D3 function that fetches JSON 。它不会将 Ruby 哈希或数组转换为 JavaScript 对象。

在 Ruby 中,您可以通过调用 to_json 将哈希或数组转换为 JSON。

在 JavaScript 中,您可以通过调用 JSON.parse 将 JSON 字符串转换为对象。

关于javascript - Jekyll 破坏 JSON 文件。箭头 ("=>")而不是 ":",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45785482/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com