如何更新 dom-repeat 模板以在本地存储中显示新添加的项目?
How to update the dom-repeat template to display newly added item in localstorage?
<template id="repeat" is="dom-repeat" items="[[model]]" as="day">
<component model="[[day]]"></component>
</template>
我正在使用 Iron 本地存储将数据加载为 [[模型]]。
使用localStorage.setItem(...) 更新数据时,如何让模板更新和显示新添加的对象?
现在新对象只在页面刷新后显示,因为它会重新加载本地存储。
我尝试使用另一个 Whosebug post 所说的 this.$.repeat.render()
,但没有任何效果。
我将使用的模式是:
<template>
<iron-localstorage name="my-app-storage" value="{{model}}" on-iron-localstorage-load-empty="initializeDefaultValue"></iron-localstorage>
<template id="repeat" is="dom-repeat" items="[[model]]" as="day">
<component model="[[day]]"></component>
</template>
</template>
然后当你想更新本地存储时,只需更新对象because:
iron-localstorage automatically saves the value to localStorage when value is changed. Note that if value is an object auto-save will be triggered only when value is a different instance.
this.set('model', model);
<template id="repeat" is="dom-repeat" items="[[model]]" as="day">
<component model="[[day]]"></component>
</template>
我正在使用 Iron 本地存储将数据加载为 [[模型]]。 使用localStorage.setItem(...) 更新数据时,如何让模板更新和显示新添加的对象?
现在新对象只在页面刷新后显示,因为它会重新加载本地存储。
我尝试使用另一个 Whosebug post 所说的 this.$.repeat.render()
,但没有任何效果。
我将使用的模式是:
<template>
<iron-localstorage name="my-app-storage" value="{{model}}" on-iron-localstorage-load-empty="initializeDefaultValue"></iron-localstorage>
<template id="repeat" is="dom-repeat" items="[[model]]" as="day">
<component model="[[day]]"></component>
</template>
</template>
然后当你想更新本地存储时,只需更新对象because:
iron-localstorage automatically saves the value to localStorage when value is changed. Note that if value is an object auto-save will be triggered only when value is a different instance.
this.set('model', model);