Binding 如何在不重新测试属性的情况下更新聚合物绑定?

Binding 如何在不重新测试属性的情况下更新聚合物绑定?,binding,polymer,Binding,Polymer,我有以下情况: 从数组中呈现项的自定义元素 <dom-module id="shopping-cart"> <template> <style> :host { display: block; } </style> <template is="dom-repeat" items=[[cartItems]]> <tr> <td>[[item.name]]

我有以下情况: 从数组中呈现项的自定义元素

<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
对象。我希望在更改数组时绑定会更新,但它没有更新。推送新元素或删除其他元素时,更改不会反映在
购物车
元素中。我试图手动触发
购物车项目更改
事件,但仍然没有帮助。唯一导致绑定刷新的似乎是为
app.cartItems
属性分配一个新数组,但这似乎不正确。我觉得我错过了一些简单的步骤,但我不知道是哪一步。有什么想法吗?

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

  • 推送(路径,项1,[…,项n])
  • 弹出(路径)
  • 取消移位(路径,项1,[…,项n])
  • 移位(路径)
  • 拼接(路径、索引、移除计数、[item1、…、itemN])
您需要为Polymer使用其中一个,以获得有关更改的通知。

请参阅

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

  • 推送(路径,项1,[…,项n])
  • 弹出(路径)
  • 取消移位(路径,项1,[…,项n])
  • 移位(路径)
  • 拼接(路径、索引、移除计数、[item1、…、itemN])

您需要使用其中一个链接才能获得更改通知。

是的,您是对的,我可以将两个链接中的信息组合在一起以获得正确的更改。我使用了
app.push(“cartItems”,item)
来获取要显示在购物车中的项目,为了改变数组中对象的属性,我使用了相同的方法,使用了
path
:获取项目的索引,
var path=“cartItems.”+itemIndex;应用程序集(路径+“.quantity”,产品.quantity)//[…]
并分别更新了每个属性。是的,你是对的,我能够将两个链接中的信息合并在一起,以获得正确的结果。我使用了
app.push(“cartItems”,item)
来获取要显示在购物车中的项目,为了改变数组中对象的属性,我使用了相同的方法,使用了
path
:获取项目的索引,
var path=“cartItems.”+itemIndex;应用程序集(路径+“.quantity”,产品.quantity)//[…]
并分别更新每个属性。