1
我有以下的情况: 这使得从一个阵列如何更新聚合物结合而不重新生成财产?
<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
属性分配一个新的数组,但这看起来不正确。我觉得我错过了一些简单的步骤,但我无法弄清楚哪一个。有任何想法吗?
是的,你是对的,我能够结合来自两个链接的信息,以得到它的权利。我使用'app.push(“cartItems”,item)'让项目出现在购物车中,并且为了改变数组内部对象的属性,我使用了与'path'相同的方法:该项目的索引,'var path =“cartItems”。 + itemIndex; app.set(path +“.quantity”,product.quantity); // [...]'并单独更新每个属性。 –