Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
5 ตอบกลับ
22339 มุมมอง

I want to break the looping but I dont have any information about this .

please help me how can do it.

thank you so much

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Sonny V is correct.  You can achieve this by checking a condition.  Set foo == True when you want to break the loop, ie when i == 3.  It does loop through the rest of the items however, so isn't an elegant solution.

<div>

    <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>

</div>

 
If it doesn't have to be a purely qweb solution, you can write a python function to break at the correct place / filter the items. so the qweb only has to output them.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

you can use this code in the place for you page break:

 <!-- Pagebreak -->
                        <t t-if="p_index &lt; p_size - 1">
                            <![CDATA[
                                </tbody>
                            </table>
                            <p style="page-break-before:always;"> </p>
                            <table class="table table-condensed">
                            ]]>

                       </t>

อวตาร
ละทิ้ง

This is not what was originally asked. Breaking a loop is unrelated to a page break in html.

คำตอบที่ดีที่สุด

You haven't really provided us with a lot of info but the following might work?

<div>
    <t t-foreach="[1, 2, 3]" t-as="i">
        <t t-if="condition">
            <p><t t-esc="i"/></p>
        </t>
    </t>
</div>

you loop through elements, check for a condition, if the condition is not met it'll break out of the if and if you don't have any statements under the if statement it'll break out of the for loop for that iteration

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi I got the same issue,

how can i make the loop stop at item 3? is there any break; code?

example

<div>

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

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

         </t>

     </t>

</div>


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
มี.ค. 23
34322
4
พ.ค. 22
34939
How to call function in qweb? แก้ไขแล้ว
1
เม.ย. 25
11308
2
มี.ค. 15
4493
0
มี.ค. 15
4543