它是一个Django模板,它有FOR LOOP并且包含1个DIV。
{% for player in players_details %}
<div data-playerId="{{ player }}" class=" my_player_id >
.... some functionality .....
</div>
{% endfor %}
1。将在for循环中的对象中生成多个div
2.现在Model将打开上面的div点击
//THIS IS JAVASCRIPT FUNCTION
$(".my_player_id").click(function(){
var myPlayer = $(this).data('playerId');
console.log(myPlayer);
$("#myModal").modal();
});
3。现在问题是我没有在javascript中获取对象
Inside DIV
<div data-playerId="{{ player }}"
Inside JS
var myPlayer = $(this).data('playerId');
4。注意:它适用于1个对象数据(object.data)
This is working
<div data-playerId="{{ player.name }}"
Inside JS
var myPlayer = $(this).data('playerId');