首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在不恢复性能的情况下更新聚合物结合?

如何在不恢复性能的情况下更新聚合物结合?
EN

Stack Overflow用户
提问于 2015-11-08 12:40:04
回答 1查看 80关注 0票数 0

我有以下情况:一个自定义元素,它从数组中呈现项

代码语言:javascript
复制
<dom-module id="shopping-cart">
 <template>
  <style>
    :host {
      display: block;
    }
  </style>
  <template is="dom-repeat" items=[[cartItems]]>
    <tr>
      <td>[[item.name]]</td>
      <td><span>[[item.quantity]]</span> <small>[[item.uom]]</small></td>
      <td><span>[[item.cost]]</span> <small>lei</small></td>
    </tr>
  </template>
 </template>
<script>
  (function() {
  'use strict';

  Polymer({
    is: 'shopping-cart',

    properties: {
      cartItems: {
        type: Object,
        value: []
      }
    }
  });
})();
</script>
<!-- And this is the container -->
<template is="dom-bind" id="app">
  <shopping-cart cart-items="[[cartItems]]"></shopping-cart>
</template>

我正在根据一些事件操作app.cartItems对象。我期望绑定在更改数组时更新,但它没有。在推送新元素或删除其他元素时,这些更改没有反映在shopping-cart元素中。我试图手动触发cart-items-changed事件,但这仍然没有帮助。导致绑定刷新的唯一原因似乎是为app.cartItems属性分配一个新数组,但这似乎不正确。我觉得我错过了一些简单的步骤,但我不知道是哪一步。有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-08 15:23:56

看见

每一种聚合物元素都有以下阵列突变方法:

  • 推(路径,item1,.,itemN)
  • pop(路径)
  • 平移(路径,item1,.,itemN)
  • 移位(路径)
  • 拼接(路径、索引、removeCount、item1、.、itemN)

你需要使用其中之一的聚合物,以得到通知的变化。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33594055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档