我不确定我的代码中发生了什么,可以使用一些指针来了解可能发生的事情。
一点背景......
我想要#14;披萨"将其更改传递给" selectedItem"当什么东西在"披萨"变化。
现在代码:
以下是我的子元素js:
Polymer({
is:"order-pizza-mod",
behaviors: [
Polymer.NeonSharedElementAnimatableBehavior
],
properties: {
mobile: {
observer: "screenSizeChanged"
},
pizza: {
notify: true,
observer: "selectedPizza"
},
....
addToOrder: function () { //this is the function that will need to update my parent element.
this.set("pizza.ADD",true);
this.fire('selectPage',4);
console.log("SENT CHANGES");
console.log(this.pizza);
},
....
以下是我的父元素HTML和JS:
HTML:
<neon-animated-pages id="pages" selected="[[selected]]" class="overflow-catch">
...
<!-- 7 --><order-pizza-mod pizza="{{selectedItem}}"></order-pizza-mod>
...
</neon-animated-pages>
JS:
Polymer({
is:"page-order",
behaviors: [
Polymer.NeonSharedElementAnimatableBehavior
],
properties: {
...
selectedItem: {
observer:"selectionChanged"
},
},
....
selectionChanged: function () {
console.log("YAY, got all the things!");
},
....
关于可能发生的事情的任何想法?
答案 0 :(得分:1)
所以我找到了一个解决方案但不是很好。
问题在于:
.server("http://10.0.3.2:1337/parse/")
目前聚合物存在一个未解决的问题,即“this.set”功能不会触发通知。我也尝试了“notifyPath”,但这不起作用。我发现迫使聚合物触发通知的唯一方法是将变量重新分配给这样的新对象:
this.set("pizza.ADD",true);
这很麻烦,但可以强制聚合物通知数据绑定变量。现在,如果有人知道更好的方法,请告诉我。
答案 1 :(得分:1)
而不是这个
properties: {
selectedItem: {
observer:"selectionChanged"
}
}
这样做
observers: [
'selectionChanged(selectedItem.*)'
]
问题是selectedItem
仅在引用全新对象时才被视为已更改。但您正在尝试观察selectedItem
的属性的更改,这需要您观察selectedItem.*
。