使用聚合物渲染一個對象數組時,它不斷啓動我一個例外。聚合物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