只是一个小问题,我现在无法理解:
我有一个表格中显示的对象列表。对象值之一是分数。我可以使用 Django 模板标签将其显示为数字,但我想使用我的 jquery 插件来显示星星。不知道如何迭代这个。我正在尝试这个:
{% for result in mylist %}
<td>{{ result.type }}</td>
<td>{{ result.description }}</td>
<td>{{ result.rating.votes }}</td>
<td><div class="raty" data-number="{{ result.rating.score }}"></div></td>
{% endfor %}
再往下,我得到了这个:
<script>
$('.raty').raty({ readOnly: true, score: $('.raty').attr('value') });
</script>
问题是它使用 jquery 为每个对象显示相同的分数..
编辑:我得到了它的工作:
<script>
$('.raty').each(function() {
$(this).raty({ readOnly: true, score: $(this).attr('data-number') });
});
</script>