我正在显示从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 :(得分:0)
这对我有用:
仅在接受了projectID时才显示项目数据。
<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>
答案 1 :(得分:0)
在我不确定我是否正确使用它之前没有使用过dom-if。问题上面的代码是这个条件的正确用法。我无意中使用了错误的变量,它应该是[[subSession.presentation]]。