我有一个包含弹出式页面的模板。我循环遍历从视图中获得的列表中的所有值,并希望在弹出窗口中包含来自列表中每个元素的信息。
页1.html:
{% include "popup.html" %}
...
{% for element in someList %}
<div class="col s3 some-button"><a onclick="$(showPopup('popup'));">More Info</a></div>
{% endfor %}showPopup是一个Javascript函数,它将显示弹出窗口。
在popup.html中,我从上面的for循环引用element:
popup.html
...
{{ element }}
...但是popup.html模板似乎无法从for循环中找到element,因为没有显示任何内容。是否有办法使popup.html能够引用element?
发布于 2016-10-27 21:44:10
我发现用它来达到我的目的是有效的:
页1.html:
...
{% for element in someList %}
{% include "popup.html" with element=element %}
<div class="col s3 some-button"><a onclick="$(showPopup('popup'));">More Info</a></div>
{% endfor %}发布于 2016-10-27 19:12:45
在链接中,可以添加属性data-element="{{ element }}",而在与链接关联的onclick方法中,可以检索如下所示的值:
var el = $(this).data("element");现在,将el传递到您的弹出窗口。
https://stackoverflow.com/questions/40292131
复制相似问题