2016-09-28 113 views
0

我对聚合物非常陌生,我想在下方执行... 我有一个绑定变量{{readonly}},通过它我发送数据从父DOM的HTML到儿童DOM的HTML,在高分子从父元素中获取属性后,控制子元素的dom-if

的代码片段大致是这样的..

呼吁从父子DOM,(我已经初始化只读在父母与“真” )

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

我发现,在子元素首先创建被激发,那么HTML是画,那么本地DOM的所有属性正从父值。

但我想的是,DOM-如果后,才从父{{只读}}获得的价值,这样我就可以调用正确的子儿-DOM [callsome1,或验证callsome2]

任何人都可以请我提供一个想法/窍门,我怎么能达到必要的?

在此先感谢

回答

1

而是调用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将被更新编辑。

+0

谢谢:)它的工作 – Liakat