【问题标题】:Jekyll ruining JSON file. Arrows ("=>") instead of ":"Jekyll 破坏 JSON 文件。箭头(“=>”)而不是“:”
【发布时间】:2018-01-28 20:12:46
【问题描述】:

我想在 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 到处都是 =>

有人可以帮助我吗?

【问题讨论】:

    标签: javascript json d3.js jekyll liquid


    【解决方案1】:

    siteJekyll 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 字符串转换为对象。

    【讨论】:

      猜你喜欢
      • 2012-09-14
      • 2018-06-30
      • 1970-01-01
      • 1970-01-01
      • 2011-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多