我有以下情况:一个自定义元素,它从数组中呈现项
<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属性分配一个新数组,但这似乎不正确。我觉得我错过了一些简单的步骤,但我不知道是哪一步。有什么想法吗?
发布于 2015-11-08 15:23:56
看见
每一种聚合物元素都有以下阵列突变方法:
你需要使用其中之一的聚合物,以得到通知的变化。
https://stackoverflow.com/questions/33594055
复制相似问题