![](/img/trans.png)
[英]Control the dom-if of child element, after getting a property from parent element
[英]Make 'dom-if' check the condition against a property in another element?
我有一些看起來像這樣的代碼:
..
<template is="dom-if" if="_myMethod()">
<div>Hello world</div>
</template>
..
_myMethod
看起來像這樣:
_myMethod: function(){
return this.$.someOtherObject.someList.size() == 0;
}
如您所見,該方法從頁面中的其他polymer-element
返回值。 但是當我的其他 polymer-element
發生變化時,如何更改dom-if
的“狀態”呢?
我知道,如果我將一個值傳遞給該方法,例如: _myMethod(someValue)
如果someValue
更改,它將更新dom-if
,但是我需要“觀察”另一個polymer-element
的更改。 我該怎么做?
經過一些試驗,我得出以下結論:
..
<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;
}
dom-if
其他元素上的值(數組)發生更改,則dom-if
現在將更新。 不確定是否存在錯誤(帶有數組),但是我嘗試直接綁定到someOtherObject.someList
並同步兩個元素之間的更改,它們同步了,但是事件未正確觸發,因此dom-if
無法更新。 :(
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.