我在模板中继器中有几个有条件标记的元素。现在,当我更新数据时,if 条件似乎没有生效,这导致undefined
传递到处理这些元素数据的函数中。
使用该restamp
属性似乎没有帮助(https://www.polymer-project.org/1.0/docs/devguide/templates.html#dom-if)。到目前为止,我只能通过清空this.items = [];
发起新请求的更改处理程序中的 items 属性 () 来解决这个问题。
This works, but results in the template being empty for a short amount of time before the new data gets displayed. Not necessarily a problem, but I wonder if I'm doing something wrong.
Here are the corresponding parts of the code:
<template>
...
<iron-ajax
id="ironajax"
url="https://www.url.com/api"
params="{{ajaxParams}}"
handle-as="json"
on-response="handleResponse"
on-error="handleError">
</iron-ajax>
...
<template is="dom-repeat" items="{{items}}" id="items">
...
<template is="dom-if" if="{{item.info.subtitle}}">:
<span>{{truncateSubtitle(item.info.subtitle)}}</span
</template>
...
Polymer({
is: 'my-element',
properties: {
query: {
type: String,
value: ''
}
...
items: {
type: Array,
value: []
}
}
...
handleChange: function() {
if (this.value !== '') {
this.items = [];
this.query = this.value;
this.$.ironajax.generateRequest();
}
}
...