[英]Make 'dom-if' check the condition against a property in another element?
I have some code that looks like this: 我有一些看起来像这样的代码:
..
<template is="dom-if" if="_myMethod()">
<div>Hello world</div>
</template>
..
_myMethod
looks like this: _myMethod
看起来像这样:
_myMethod: function(){
return this.$.someOtherObject.someList.size() == 0;
}
As you can see the method return a value from some other polymer-element
in the page. 如您所见,该方法从页面中的其他
polymer-element
返回值。 But how do I get the dom-if
to change it's "state" when my other polymer-element
changes? 但是当我的其他
polymer-element
发生变化时,如何更改dom-if
的“状态”呢?
I know that if I pass a value to the method, like this: _myMethod(someValue)
if someValue
changes it will update the dom-if
, but I need to "observe" a change in another polymer-element
. 我知道,如果我将一个值传递给该方法,例如:
_myMethod(someValue)
如果someValue
更改,它将更新dom-if
,但是我需要“观察”另一个polymer-element
的更改。 How do I do what I wanna do? 我该怎么做?
With some experimentation I ended up with the following: 经过一些试验,我得出以下结论:
..
<my-other-element on-some-list-changed="_notifyChange" id="someOtherObject">
</my-other-element>
..
..
<template is="dom-if" if="_myMethod(didChange)">
<div>Hello world</div>
</template>
..
..
_notifyDidChange: function()
{
this.didChange = !this.didChange;
}
_myMethod: function(didChange){
return this.$.someOtherObject.someList.size() == 0;
}
The dom-if
will now update if the value (array) on the other element changes. dom-if
其他元素上的值(数组)发生更改,则dom-if
现在将更新。 Not sure if there's a bug (with arrays), but I tried binding to someOtherObject.someList
directly and sync changes between the two elements, they synced, but events weren't triggered properly and thus the dom-if
wouldn't update. 不确定是否存在错误(带有数组),但是我尝试直接绑定到
someOtherObject.someList
并同步两个元素之间的更改,它们同步了,但是事件未正确触发,因此dom-if
无法更新。 :( :(
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.