Just a small problem i can't get my head around right now:
I have a list of objects presented in a table. One of the objects values is a score. I can use a Django template tag to show this as a number but i want to use my jquery plug-in to show stars instead. Not sure how to iterate over this. I'm trying this:
{% 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 %}
And further down i got this:
<script>
$('.raty').raty({ readOnly: true, score: $('.raty').attr('value') });
</script>
The problem is that it shows the same score for every object with the jquery..
EDIT: I got it to work with this:
<script>
$('.raty').each(function() {
$(this).raty({ readOnly: true, score: $(this).attr('data-number') });
});
</script>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…