首页 文章

Odoo 10:退出Qweb循环

提问于
浏览
0

我有一个以下代码:

<t t-foreach="doc.order_lines_layouted()" t-as="page">
     <t t-foreach="page" t-as="layout_category">
         <t t-foreach="layout_category['lines']" t-as="l">
              <t t-if="l.product_id.product_tmpl_id.type == 'product'" > 

                  



<p>Bill To: </p> <!-- Adds customers contact details on top right corner --> <div t-field="doc.partner_invoice_id" t-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;contactname&quot;, &quot;name&quot;, &quot;phone&quot;, &quot;email&quot;, &quot;fax&quot;], &quot;no_marker&quot;: True, &quot;phone_icons&quot;: True, &quot;email_icons&quot;: True}"/> <p>Customer VAT#:&#160; <span t-field= "doc.partner_invoice_id.vat"/>
Customer#:&#160;<span t-field= "doc.partner_id.id"/> </p> </t> </t> </t> </t>

一旦满足t-if条件,我想退出循环 . 我怎样才能做到这一点?在qweb中是否存在 exit(); 之类的内容?

Info: 我知道下面的解决方案,但这不是一个优雅的解决方案:

<t t-set="foo" t-value="False"/>

    <t t-foreach="[1, 2, 3, 4, 5, 6]" t-as="i">

        <t t-if="foo == False">

             <p><t t-esc="i"/></p>

             <t t-if="i==3">

                 <t t-set="foo" t-value="True"/>

             </t>

        </t>

    </t>

1 回答

  • 0

    对于qweb有一个像 <t t-break/> 这样的选项会很好,但是AFAIK没有什么可以让你做到这一点 . 您可以做的是在进入t-foreach循环之前,通过从集合中过滤掉所有不需要的元素来准备要迭代的数据集或集合

相关问题