2015-11-30 22 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]]。