2015-11-30 23 views
0

我正在顯示從JSON文件中提取的數據,其中一個JSON屬性可能有或沒有值。我只想在JSON文件中的值存在時才顯示文本。我試過以下,但沒有顯示。聚合物中數據項的有條件顯示

<template is="dom-repeat" items="[[session]]" as="subSession"> 
.... Display other values from the JSON file 
<template is="dom-if" if="{{subSession.track.presentation}}"> 
    <div class="session-meta layout horizontal"> 
    <iron-icon class="session-meta-icon" icon="class"></iron-icon> 
    <span>Presentation Available</span> 
    </div> 
</template> 

回答

0

下面是什麼工作對我來說:

顯示項目的數據只有當它的專案編號被接受。

<template is="dom-repeat" items="{{projects_list}}" as="project"> 
     <template is="dom-if" if="{{project_check(project.projectID)}}"> 
     ...display project values here... 
     </template> 
</template> 
<script> 
project_check: function(projectID) { 
     console.log('project_check:'); 
     console.log(projectID); 
     //check if projectID is accepted here. 
     //return true or false to render or not the template. 
    }, 
</script> 
+0

謝謝,你發現project_check腳本是必要的嗎?我能夠解決這個問題,只使用dom-if語句。 – tw1742

0

在沒有使用dom-if之前我不確定是否正確使用了這個。以上代碼中的代碼是這個條件的正確用法。我無意中使用了錯誤的變量,它應該是[[subSession.presentation]]。