0

是否可以在 TimelineJs 实例中从页面中的变量加载 JSON 数据?

  <div id="timeline-embed"></div>
  <script type="text/javascript">

    var timeline_config = {
     width: "100%",
     height: "100%",
     source: 'example_json.json'
    }
  </script>
  <script type="text/javascript" src="../compiled/js/storyjs-embed.js"></script>

这是来自timelineJS 示例的默认代码。基本上我正在尝试source: 'example_json.json'

source: '{
    "timeline":
    {
        "headline":"Sh*t People Say",
        "type":"default",
        "text":"People say stuff",
        "startDate":"2012,1,26",
        "date": [
            {
                "startDate":"2011,12,12",
                "endDate":"2012,1,27",
                "headline":"Vine",
                "text":"<p>Vine Test</p>",
                "asset":
                {
                    "media":"https://vine.co/v/b55LOA1dgJU",
                    "credit":"",
                    "caption":""
                }
            },
            {
                "startDate":"2012,1,26",
                "endDate":"2012,1,27",
                "headline":"Sh*t Politicians Say",
                "text":"<p>In true political fashion, his character rattles off common jargon heard from people running for office.</p>",
                "asset":
                {
                    "media":"http://youtu.be/u4XpeU9erbg",
                    "credit":"",
                    "caption":""
                }
            }
]
    }
}'

但它不起作用

4

1 回答 1

0

问题是您将 JSON 对象作为字符串传递。删除引号,它应该可以工作。应该是这样的:

    source: {
            "timeline": { 
              ...
            }
    }

我在JSFiddle上整理了一个工作示例

于 2013-08-18T11:44:57.413 回答