我一直在玩http://almende.github.com/chap-links-library/timeline.html,它允許用戶添加/編輯/刪除時間軸上的事件。關閉或刷新瀏覽器會將其重置爲預先加載的數據源 - JSON,表格信息或Google Spreadsheet。用戶添加或更改沒有保存。保存用戶編輯的時間軸?
如何讓用戶更改持久?
我已經使用HTML5的localStorage之前保存的文本,複選框,並選擇框條目等但這個時間表的唯一入口是:
DIV ID =「mytimeline」
具有與之相關的腳本:
// Instantiate our timeline object.
timeline = new links.Timeline(document.getElementById('mytimeline'));
這是對構建時間軸容器的JS的引用。
任何想法或示例或指針?
謝謝。
更新: 這是我到目前爲止有:
//Check to see if localStorage is supported
var db = getLocalStorage() || alert("Local Storage Not supported in this browser. Try updating to the latest Firefox, Chrome or Safari browsers.");
function getLocalStorage() {
try {
if(window.localStorage) return window.localStorage;
}
catch (e)
{
return undefined;
}
}
//Store Timeline Data to localStorage
function storeTimelineData(){
var data=timeline.getData();
localStorage.setItem('mytimeline', JSON.stringify(data));
var storedData=JSON.parse(localStorage.getItem('myTimeline'));
// clear storage
function clearLocal() {
clear: localStorage.clear();
return false;
}
,我也做了這些改變 - 身體的onload = 「storedData()」,以嘗試加載localStorage的保存價值和改變DIV ID = 「mytimeline」onmouseup =「storeTimelineData()」用於在對時間軸進行更改時存儲值。
對時間線的更改正在保存在localStorage中,我可以在控制檯中看到這些鍵/值的更改。當我刷新瀏覽器時,它們不會被加載到mytimeline中。我錯過了什麼?
謝謝。
@laaposto:爲什麼'timeline.js'標籤被刪除? –
我添加了更加準確和剛剛創建的chap鏈接庫。它沒有作爲一個標籤,當你發佈這個問題 – laaposto