如何使用聚合物1.0中的缓存功能来保存和重用元素数组

How to use cache feature in polymer 1.0 to save and reuse an array of elements?

本文关键字:保存 数组 元素 功能 缓存 聚合物 何使用      更新时间:2023-09-26

我们拥有白金元素platinum-sw-cache,可以离线管理数据。

基本上,我正在尝试创建一个元素,显示最近使用的项目列表在我的应用程序,我认为缓存是实现它的方法。

如何使用元素保存数组,以便以后使用

你能试试吗?

<dom-module id="recent-items">
 
 <template>
  <iron-localstorage name="my-app-storage"
    value="{{recentFood}}"
    on-iron-localstorage-load-empty="initializeDefault"
  ></iron-localstorage>
 <template is ="dom-repeat" items={{recentFood}}>
<div class="horizontal layout">{{item}}</div>
</template> 
</template>
<script>
  Polymer({
    is: 'recent-items',
    properties: {
      recentFood: {
        type: Array
      }
    },
    // initializes default if nothing has been stored
    initializeDefault: function() {
    	
    	var tempItems=new Array();
    	
    	tempItems[0]="Pizza";
    	
    	this.recentFood=tempItems.slice();
    	
    },
     // use path set api to propagate changes to localstorage
    makeModifications: function() {
    }
    
  });
</script>
</dom-module>