具有不同数据的嵌套循环
我有两个列表:
campaigns = [{"name":"test", "client": "test_client", "reporter": "myself", "price": 45}...]
filters = ["name", "client", "reporter"]
我希望我的表格仅显示过滤器中包含的数据。
<tbody>
{% for campaign in campaigns %}
<tr role="row" class="odd">
{% for filter in filters%}
<td>{{campaign.filter}}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
这是两个不同的列表,但我想使用过滤器列表来获取活动列表中的键,我尝试了多次写入,但没有成功:
{{campaign[filter]}}
{{campaign}}.{{filter}}
你有什么想法吗? 谢谢。
I have two lists:
campaigns = [{"name":"test", "client": "test_client", "reporter": "myself", "price": 45}...]
filters = ["name", "client", "reporter"]
I want my table to just display the data contained in the filter.
<tbody>
{% for campaign in campaigns %}
<tr role="row" class="odd">
{% for filter in filters%}
<td>{{campaign.filter}}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
Those are 2 differents lists, but I want to use the filters list to get the keys in the campaigns list, I tried multiple writing but it didn't work:
{{campaign[filter]}}
{{campaign}}.{{filter}}
Do you have any idea ?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此代码,我能够在嵌套循环中检索数据。万一这可能对某人有帮助。
With this code I was able to retrieve my data in a nested loop. In case this might help someone.