如何使用 Polymer 在本地存储属性和值?
How do I store attributes and values locally using Polymer?
我的目的是创建一个有指导的测验,但我想将名称和选择等内容完全存储在本地。我遵循了 Polymer 在 30 分钟内构建应用程序的指南,但他们从未涵盖如何在本地持久保存数据。
如有任何指导或建议,我们将不胜感激。
我建议您将 json 与 core-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>
我的目的是创建一个有指导的测验,但我想将名称和选择等内容完全存储在本地。我遵循了 Polymer 在 30 分钟内构建应用程序的指南,但他们从未涵盖如何在本地持久保存数据。
如有任何指导或建议,我们将不胜感激。
我建议您将 json 与 core-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>