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

I want to compare the javascript var with odoo's t-if. But it gives me an error.

Xml file:

<odoo>

    <data>
    <record id="product_product_inherit" model="ir.ui.view">
                <field name="name">product.template.inherit</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="product.product_template_only_form_view"/>
        <field name="arch" type="xml">
            <field name="default_code" position="after">
                <field name="gifpath" widget="image"/>
            </field>
        </field>
              </record>

       <template id="website_sales_inh" name="webiste_sales_inherit" inherit_id="website_sale.products_item">

          <xpath expr="//span[@class='d-flex h-100 justify-content-center align-items-center']" position="replace">
        <script type="text/javascript">
            var list = document.querySelectorAll('img');

            var i;
            var imgsrc=[];
            var trigger;
            for(i=0;i<3;i++)
            {
                imgsrc[i] = list[i].src;
                list[i].addEventListener("mouseover",function()
                {
                 trigger = 1;
                });
                list[i].addEventListener("mouseout",function()
                {
                  trigger = 0;
                });
            }
        </script>
        <t t-if="trigger == 1">
                      <span t-field="product.image_1920"
                                t-options="{'widget': 'image', 'preview_image': 'gifpath'}"
                                class="d-flex h-100 justify-content-center align-items-center"/>
        </t>
           
        <t t-elif="trigger == 0">
            <span t-field="product.image_1920"
                        t-options="{'widget': 'image', 'preview_image': 'image_1024' if product_image_big else 'image_256'}"
                        class="d-flex h-100 justify-content-center align-items-center"/>

        </t>
          </xpath>

       </template>

    </data>

</odoo>

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

Hello,

Please try to using this way:


<t t-jquery="[t-set*='count']">

          <t t-js="ctx">

              var table = document.getElementById("tableId");

                        alert(table.offsetHeight);        

  

              <t t-if="table">

          </t>

</t>

   Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

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

provided template is rendered at server side (python) so you will never get the value of the variable 'trigger' 

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Get data from JS file to XML file แก้ไขแล้ว
1
ส.ค. 20
9097
2
ก.ค. 24
1361
2
มิ.ย. 23
42566
1
ธ.ค. 22
3411
2
ธ.ค. 22
4353