只有当变量具有使用jquery的值时才在html中显示逗号? [英] Show comma in html only if the variable has value using jquery?
本文介绍了只有当变量具有使用jquery的值时才在html中显示逗号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样一个表:
<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th>Project Name</th>
<th>Tape-ID</th>
<th>Video Type</th>
<th>Date Created</th>
<th>Director</th>
<th>Camera Person</th>
<th>Editor</th>
<th>Tag</th>
</tr>
</thead>
<tbody>
{% load endless %}
{% paginate 8 a %}
{% for choice, i in a %}
<tr>
<td><input type="checkbox" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" onchange="checkChecked()" /></td>
<td>{{ choice.name }}</td>
<td>{{ choice.tape_id }} </td>
<td>{{ choice.video_type }}</td>
<td>{{ i }}</td>
<td>{{ choice.director }}</td>
<td>{{ choice.cameraman }}</td>
<td>{{ choice.editor }}</td>
<td>{{ choice.tag1 }}, {{ choice.tag2 }}, {{ choice.tag3 }}, {{ choice.tag4 }},
{{ choice.tag5 }}, {{ choice.tag6 }}, {{ choice.tag7 }}, {{ choice.tag8 }},
{{ choice.tag9 }}, {{ choice.tag10 }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
这些变量 {{choice ...}}
可能有或没有价值。虽然是顺序的。变量upto 3可以有值,并且没有任何值在3之后。如果没有值,它会像这样:
These variable {{ choice...}}
may or may not have value. It is sequential though. The variable upto 3 can have values and none of have values after 3. If there's no value it comes like this:
water, pollution, hello, , , , , ,
如果没有值,我不想显示逗号。
I don't want to show comma if there's no value. How can I do this?
推荐答案
尝试使用
Try using
{{#choice.tag1}}
{{ choice.tag1 }}{{#choice.tag2}},{{/choice.tag2}}
{{/choice.tag1}}
每次出现。最后一项是:
for each occurrence. Last one will be:
{{#choice.tag10}}
{{ choice.tag10 }}
{{/choice.tag10}}
这篇关于只有当变量具有使用jquery的值时才在html中显示逗号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文