2015-03-03 86 views
0

我的意圖是創建一個指導性測驗,但我想在本地存儲名稱和選擇等內容。我在30分鐘內遵循Polymer構建了一個應用程序,但他們從未涉及如何在本地保存數據。如何使用聚合物本地存儲屬性和值?

任何指導或建議將不勝感激。

+1

https://www.polymer-project.org/docs/elements/core-elements.html#core - 本地存儲 – 2015-03-03 13:36:54

+1

這不是一個真正的聚合物問題。 http://diveintohtml5.info/storage.html – 2015-03-03 13:38:55

+0

謝謝保羅的鏈接和信息,它看起來正是我所需要的。 – Jebzaki 2015-03-03 13:40:38

回答

2

我會建議你使用json核心AJAX元素。

mydata.json

[{ 
    "question":"A question here", 
    "answer":"The answer", 
    "other":"and so on.." 
}, 
{ 
    "question":"Another question here", 
    "answer":"The answer", 
    "other":"and so on.." 
}] 

的index.html

<core-ajax id='ajax' url='mydata.json' on-response='{{response}}' handleAs='json'> 
<template repeat='{{data in json}}'> 
    <p>{{data.question}}</p> 
    <p>{{data.answer}}</p> 
</template> 
<script> 
    Polymer({ 
     json: null, 
     ready: function(){ 
      this.$.ajax.go(); 
     }, 
     response: function(e){ 
      this.json = e.detail.response; 
     } 
    }); 
</script> 
+1

謝謝你們兩位保羅給了我一個完整的答案。 – Jebzaki 2015-03-03 14:36:55