使用聚合物渲染一个对象数组时,它不断启动我一个例外。聚合物dom重复问题
下面是从服务器检索的数据模型:
{
"lastUpdate":"yyyy-MM-ddTHH:mm:ss.mmm",
"info": [
{
"title": "Some nice title"
},
...
]
}
这里是我的聚合物组分的模板:
<dom-module is="items-list">
<template>
<dl>
<dt>last update:</dt>
<dd>[[$response.lastUpdate]]</dd>
<dt>total items:</dt>
<dd>[[$response.info.length]]</dd>
</dl>
<template is="dom-repeat" items="{{$response.info}}">
{{index}}: {{item.title}}
</template>
</template>
<script src="controller.js"></script>
</dom-module>
而这里的控制器:
'use strict';
Polymer(
{
properties: {
info: {
type: Array
},
$response: {
type: Object,
observer: '_gotResponse'
}
},
_gotResponse: function(response)
{
console.log(response);
if (response.info.length)
{
try
{
//here I try to set info value
}
catch(e)
{
console.error(e);
}
}
},
ready: function()
{
//set some default value for info
},
attached: function()
{
//here I request the service for the info
}
}
);
如果试图设置信息值如:
this.info = response.info;
this.set('info', response.info);
this.push('info', response.info[i]); //inside a loop
但渲染的第一个项目之后的结果断裂,推出的例外是: “遗漏的类型错误:空的无法读取属性‘价值’”
做,问题仍然发生 – Wolfchamane