2016-09-28 62 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