0

我有这段代码可以帮助我在我的页面上显示 Verite Timeline,所以:

<div id="timeline-embed"></div>
      <script type="text/javascript">
        var timeline_config = {
         width: "100%",
         height: "100%",
         debug: true,
         rows: 2,
         source: {
    "timeline":
    {
        "headline":"Sh*t People Say",
        "type":"default",
        "text":"People say stuff",
        "startDate":"10/4/2011 15:02:00",
        "date": [
            {
                "startDate":"10/4/2011 15:10:00",
                "endDate":"10/4/2011 15:55:00",
                "headline":"FIRST",
                "text":"<p>FIRSTTEXT</p>",
                "asset":
                {

                    "caption":"yessss"
                }
            },
            {
                "startDate":"10/4/2011 17:02:00",
                "endDate":"10/4/2011 18:02:00",
                "headline":"SECOND",
                "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":""
                }
            }
        ]
    }
}

        }
      </script>

所以现在我想添加新元素source:date

{
                "startDate":"CurrentDate + zajson",
                "endDate":"10/4/2011 18:02:00",
                "headline":"place.name",

                "asset":
                {
                    "media":"http://youtu.be/u4XpeU9erbg",
                    "credit":"",
                    "caption":""
                }
            }

所以场外我有一个变量:

var place.name;
var zajson;

并且当我单击时,<button>Add to timeline</button>我想将新元素(如上所示)添加到源中:在日期中,作为新的值块...

可以这样做吗?

以及如何更新源:并在添加新数据块时再次运行它???

对不起我的英语不好

4

1 回答 1

0
function addContent() {
    var content = {
        "startDate":"CurrentDate + zajson", // <-- these two probably shouldn't be in quotes, but concated
        "endDate":"10/4/2011 18:02:00",
        "headline":"place.name", // <-- this one, too
        "asset":
            {
                "media":"http://youtu.be/u4XpeU9erbg",
                "credit":"",
                "caption":""
            }
    };

    timeline_config.source.timeline.date.push(content);
}

像这样的事情应该这样做。

然后,对于按钮:

<button onclick="addContent()">Add to timeline</button>
于 2013-09-22T23:31:04.353 回答