تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
19607 أدوات العرض

Hello everybody, I need to make a loop in QWEB template for a specific number of times.

For example, I'm passing via controler a variable with a number:

'number_rows': r_number

I need to make a loop for this "number_rows" times.

Any idea?? Thanks for reading!!!

الصورة الرمزية
إهمال
الكاتب

Yea, but I need to I need to create a counter to cycle through the loop x times, no to use an array with data (as the example you make).

Any suggestion? Thanks!

أفضل إجابة

Hi,

See this example,

<t t-foreach="patients" t-as="patient">
<tr>
<td>
<t t-esc="patient.patient_name"/>
</td>
</tr>
</t>

Thanks

الصورة الرمزية
إهمال
أفضل إجابة

Hi, I had the same question.

Found a solution as:

<t t-set="qty" t-value="1"/>
<t t-foreach="range(qty)" t-as="item">
<t t-esc="item"/>
</t>
الصورة الرمزية
إهمال
أفضل إجابة
In some cases, we may need to iterate over a set of values. Suppose we have a list or a dictionary with us and we need to iterate through each value, in this case, we can use t-for each for this purpose.

Example:

<t t-foreach=”[1,2,3]” t-as=”i”>
<t t-esc=”i” /> 
</t>

This will iterate over the list [1, 2, 3] and prints each element one by one.

Regards

MUHAMMAD IMRAN
Technical and Functional Consultant  (ODOO)


Softtar Technologies Pvt. Ltd. Contact : Pakistan (+92)-3037701373
 
Address:
  
Allhafeez Shopping Mall
Lahore
Pakistan  (Branch Office)
http://sofftar.com
الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
سبتمبر 24
998
2
يوليو 23
5453
1
يونيو 23
3751
1
أبريل 23
4551
1
نوفمبر 22
3366