我正在尝试呈现一个显示评论数量(1 条评论或 xxx 条评论)的模板。我正在通过 jinja2 迭代 GAE 中的实体实例对象,但它只在第一个循环中执行脚本,之后的每个循环。我的代码有什么问题?
<table>
{% for each in courses_taught %}
<tr>
<td id="num_reviews">
<script type='text/javascript'>
var html_output = "";
var review_count ={{each.num_reviews}};
if (review_count ==1) {
html_output += "<a href='../course/{{each.key()}}'>1 review</a>";
}
else if (review_count > 1) {
html_output += "<a href='../detail/course/{{each.key()}}'>" + num_reviews + " reviews</a>";
}
else {
html_output +="<a id='trailblazer' href='../../../review/writeReview/{{each.key()}}'>Be the trailblazer</a>";
}
var reviewCount = document.getElementById("num_reviews");
reviewCount.innerHTML = html_output;
</script>
</td>
</tr>
{% endfor %}