2015-06-21 30 views
1

我們的團隊正在建造我們的第一個聚合物在一個頁面的應用程序,我們必須逆向工程被忽略的項目組成部分。我們需要在覈心腳手架中爲標題欄設置標題。這在使用JS的簡單頁面上很容易,但是一些頁面具有顯示內容的條件模板,並且每個頁面都需要它們自己的標題。聚合物腳手架:設置標題每頁:最佳方法

<core-scaffolding> 
<div id="title">Dynamic Title goes here</div> 
<core-animated-pages transitions="cross-fade"> 
    <section> 
    <div cross-fade> 
<my-element> 
<template if="{{condition1}}"></template> 
Content 1 
</template> 

<template if="{{condition2}}"></template> 
Content 2 
</template> 

<template if="{{condition3}}"></template> 
Content 3 
</template> 
</my-element> 
</div> 
    </section> 
    <section> 
    <div cross-fade></div> 
    </section> 
</core-animated-pages> 

我要在模板元素添加的屬性能夠通過標題的值,但是我不知道怎麼用JS找出哪個模板是一個這是有條件呈現(活動)。我似乎無法找到任何文件。此外,我想構建可在任何頁面上全局使用的可重用(不帶ID)的內容。

任何人都可以提供任何建議嗎?

乾杯, 大衛

回答

0

我不認爲我會使用條件模板此。如果這種情況發生了很大的變化,那麼每次更改模板的內容都會被添加或刪除。我認爲使用隱藏屬性或使用數據綁定動態更改文本會更好。

隱藏屬性

<span hidden?="{{!condition1}}">Content 1</span> 
<span hidden?="{{!condition2}}">Content 2</span> 
<span hidden?="{{!condition2}}">Content 3</span> 

數據綁定

<span>{{content}}</span> 

,那麼你可以更改其綁定在JavaScript正常人一樣。

if (condition1) { 
    this.content = 'Content 1'; 
}