![](/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.