Polymer 0.9 array push with repeat 模板
Polymer 0.9 array push with repeat template
我使用的是 Polymer 0.9,我有这个模板。
<template>
<ul>
<template is="dom-repeat" items="{{menuPages}}">
<li class="c-text">
<span>{{item.title}}</span>
</li>
</template>
</ul>
</template>
当我使用此代码段更新数据时,它没有加载
ready: function () {
this.menuPages.push({title:'hey'});
this.menuPages.push({title:'hey2'});
}
但是这有效
ready: function () {
this.menuPages = [{title:'hey'}, {title:'hey2'}];
}
为了触发 DOM 更新,您必须使用这个:
this.push('menuPages', {title:'hey'});
文档:https://www.polymer-project.org/1.0/docs/devguide/templates.html#dom-repeat
我使用的是 Polymer 0.9,我有这个模板。
<template>
<ul>
<template is="dom-repeat" items="{{menuPages}}">
<li class="c-text">
<span>{{item.title}}</span>
</li>
</template>
</ul>
</template>
当我使用此代码段更新数据时,它没有加载
ready: function () {
this.menuPages.push({title:'hey'});
this.menuPages.push({title:'hey2'});
}
但是这有效
ready: function () {
this.menuPages = [{title:'hey'}, {title:'hey2'}];
}
为了触发 DOM 更新,您必须使用这个:
this.push('menuPages', {title:'hey'});
文档:https://www.polymer-project.org/1.0/docs/devguide/templates.html#dom-repeat