简体   繁体   English

无法遍历Bootstrap Popover中的数据内容以显示Python列表数据

[英]Unable to loop over data-content in a Bootstrap Popover to display Python list data

I'm currently trying to create a local Dashboard that displays certain information about areas of our product, it does what I initially intended but I wanted to extend the functionality slightly and that is where I'm currently stuck. 我目前正在尝试创建一个本地仪表板,该仪表板显示有关我们产品区域的某些信息,它可以实现我最初打算的功能,但是我想稍微扩展一下功能,这就是我目前遇到的问题。

The Code is written in Python, this gets data from a database and puts it into a python list. 代码是用Python编写的,它从数据库获取数据并将其放入python列表中。 The list below is the output of the SQL after it's been put through a for loop and appended to the contractname list. 下面的列表是经过for循环并附加到contractname列表之后的SQL输出。

contractname = [u'Contract Almond', u'Contract Amber', u'Contract Black']

I'm then using the data from this list to render it onto a HTML page using Flask and the Jinja2 templating engine. 然后,我将使用Flask和Jinja2模板引擎使用此列表中的数据将其呈现到HTML页面上。 I have a feature on the dashboard that displays a "total number" and this is working as I intended it too but I wanted to display all the contract name's in a bootstrap popover. 我在仪表板上有一个显示“总数”的功能,该功能也按我的预期工作,但是我想在引导弹出窗口中显示所有合同名称。 If I don't use the jinja2 "for" statement it displays the popover content from the list above and looks kind of ugly. 如果我不使用jinja2“ for”语句,它将显示上面列表中的弹出窗口内容,并且看起来有点丑陋。

I'd like to display each value in the same popover box and place each value on another line within the box. 我想在同一个弹出框中显示每个值,然后将每个值放在框中的另一行上。 At the moment, it's just repeating the element each time and giving each contractname its own popover. 目前,它只是每次重复该元素,并为每个contractname提供自己的弹出框。 The data it should be looping over is in the data-content="{{ name }} . 它应该循环的data-content="{{ name }}data-content="{{ name }}

The Javascript for the popover: 弹出框的Javascript:

$(function () {
    $('[data-toggle="popover"]').popover()
});

The HTML code: HTML代码:

<div class="center">
{% for name in contractname %}
<p id="Number" data-container="body" data-toggle="popover" data-placement="top" title="Contracts" data-content="{{ name }}">{{ contracts }}</p>
{% endfor %}
</div>

上面代码的输出

I can see why it's repeating itself, as the for loop is only pointed at the <p> tag but I just cannot figure out how to loop over only the data-content="{{ name }} part of the element. 我可以理解为什么它会重复自身,因为for循环仅指向<p>标记,但是我无法弄清楚如何仅对元素的data-content="{{ name }}部分进行循环。

I've looked all over google and stackoverflow but I haven't yet found a solution that makes this work. 我已经遍及Google和stackoverflow了,但是我还没有找到一种可以解决这个问题的解决方案。 This is maybe something very simple that I'm not seeing as I've been looking at it for so long. 这可能是非常简单的事情,因为我已经看了很久了,所以一直没看到。

Any help on this would be great! 任何帮助都会很棒! Thank you in advance! 先感谢您!

This should do it. 这应该做。

<div class="center">
<p id="Number" data-container="body" data-toggle="popover" data-placement="top" title="Contracts" data-content="{% for name in contractname %}{{ name }} <br/> {% endfor %}">{{ contracts }}</p>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM