【发布时间】:2015-01-21 19:13:47
【问题描述】:
所以我有一个聚合物元素,它使用带有重复属性的嵌套模板。但它似乎无法识别传入的 JSON 对象。
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/core-icon/core-icon.html">
<link rel="import" href="bower_components/paper-input/paper-input.html">
<link rel="import" href="bower_components/paper-checkbox/paper-checkbox.html">
<link rel="import" href="bower_components/core-localstorage/core-localstorage.html">
<polymer-element name="to-do">
<template>
<style>
:host {
display: block;
background: white;
height:400px;
width: 300px;
padding: 20px;
}
paper-input {
width: 70%;
margin: 10px;
display: inline-block;
}
core-icon {
margin: 55px 10px 10px 10px;
display: inline-block;
}
paper-checkbox {
display: block;
width: 100%;
}
</style>
<paper-input floatingLabel label="Enter a Task"></paper-input> <core-icon icon="add-circle"></core-icon>
<div class="tasks">
<template repeat="{{item in tasklist}}">
<paper-checkbox label="{{item.itemName}}"></paper-checkbox>
</template>
</div>
<core-localstorage name="tasks" value="{{tasklist}}"></core-localstorage>
</template>
<script>
Polymer('to-do', {
tasklist: [
{
itemName : "Study",
isDone : true
},
{
itemName : "Cook Dinner",
isDone : false
}
],
ready: function() {
console.log(this.tasklist);
},
addObject: function() {
}
});
</script>
</polymer-element>
它似乎没有从嵌套模板块中的脚本块中获取tasklist,而是在ready 块中打印出来。
您可以在此处查看上述代码的运行演示 https://to-do-prateekjadhwani.c9.io/demo.html
谢谢
*****编辑****
由于它使用的是本地存储,它使用的是来自本地存储的任务列表中的数据,而不是通过代码迭代来更新自身。 所以,我相信这个问题已经解决了。但是,如果您认为我的推理不正确,请随时添加评论。
提前致谢。
【问题讨论】:
-
你的链接对我来说似乎是working,还是我遗漏了什么?
-
@arbitter,我刚刚检查过,链接工作正常。
标签: polymer web-component