简体   繁体   English

从父元素获取属性后,控制子元素的dom-if

[英]Control the dom-if of child element, after getting a property from parent element

I am pretty new to polymer, I wanted to perform below scenario... I have a bind variable {{readonly}} through which I send data from parent Dom-HTML to Child Dom-HTML, in Polymer 我对Polymer很陌生,我想在以下情况下执行...我有一个绑定变量{{readonly}},通过它我可以将数据从父Dom-HTML发送到Child Dom-HTML,在Polymer中

The code snippet is roughly like this.. 该代码段大致是这样的。

calling child DOM from parent,( I already initialized readonly in parent with "true") 从父级调用子DOM,(我已经在父级中以“ true”初始化了只读

<wms-griddata order-obj='{{item}}' readonly='{{readonly}}'></wms-griddata>

In child Element 在子元素中

<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;
        }

I find that in Child Element first the created is fired, then the HTML is painted, then all the properties of the local DOM is getting value from parent. 我发现在Child Element中首先触发了created ,然后绘制了HTML,然后本地DOM的所有属性都从父级获取值。

But I want that the dom-if is validated only after I get the value from the parent {{ readonly }}, so that I can call the correct sub-child-dom [ callsome1, or callsome2 ] 但是我希望仅当从父项{{ readonly }}获得值后才验证dom-if ,以便可以调用正确的sub-child-dom [ callsome1或callsome2 ]。

Can anyone please provide me an idea/trick of how can I achieve the requisite? 谁能给我一个想法/技巧,我如何达到要求?

Thanks in advance 提前致谢

Instead to call this.readOnly I think that you should pass that variable as parameter to _isReadOnly function as follows: 而不是调用this.readOnly我认为您应该将该变量作为参数传递给_isReadOnly函数,如下所示:

_isreadonly: function(readOnly){
     return readOnly == 'true';
}

So, your html will look: 因此,您的html看起来如下:

<template is="dom-if" if="{{_isreadonly(readOnly)}}">
    <callsome1></callsome1>
</template>
<template is="dom-if" if="{{!_isreadonly(readonly)}}">
    <callsome2></callsome2>
</template> 

In this case, everytime readonly change, _isreadonly function will be invoked and the DOM will be updated. 在这种情况下,每次readonly更改时,都会调用_isreadonly函数并更新DOM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM