![](/img/trans.png)
[英]Make 'dom-if' check the condition against a property in another element?
[英]Control the dom-if of child element, after getting a property from parent element
我對Polymer很陌生,我想在以下情況下執行...我有一個綁定變量{{readonly}},通過它我可以將數據從父Dom-HTML發送到Child Dom-HTML,在Polymer中
該代碼段大致是這樣的。
從父級調用子DOM,(我已經在父級中以“ true”初始化了只讀 )
<wms-griddata order-obj='{{item}}' readonly='{{readonly}}'></wms-griddata>
在子元素中
<dom-module id="wms-griddata">
.....
<template is="dom-if" if="{{_isreadonly()}}">
<callsome1></callsome1>
</template>
<template is="dom-if" if="{{!_isreadonly()}}">
<callsome2></callsome2>
</template>
<script>
Polymer({
is : 'wms-griddata',
properties: {
readonly: {
type: String
}
.......
.......
_isreadonly: function(){
if(this.readonly == 'true')
return true;
else
return false;
}
我發現在Child Element中首先觸發了created ,然后繪制了HTML,然后本地DOM的所有屬性都從父級獲取值。
但是我希望僅當從父項{{ readonly }}獲得值后才驗證dom-if ,以便可以調用正確的sub-child-dom [ callsome1或callsome2 ]。
誰能給我一個想法/技巧,我如何達到要求?
提前致謝
而不是調用this.readOnly
我認為您應該將該變量作為參數傳遞給_isReadOnly
函數,如下所示:
_isreadonly: function(readOnly){
return readOnly == 'true';
}
因此,您的html看起來如下:
<template is="dom-if" if="{{_isreadonly(readOnly)}}">
<callsome1></callsome1>
</template>
<template is="dom-if" if="{{!_isreadonly(readonly)}}">
<callsome2></callsome2>
</template>
在這種情況下,每次readonly
更改時,都會調用_isreadonly
函數並更新DOM。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.