简体   繁体   English

如何在JavaScript(Odoo11)中读取Qweb变量

[英]How to read Qweb variable in javascript (Odoo11)

I have the following code: 我有以下代码:

 <t groups="website_sale.group_website_multi_image">
  <t t-set="variant_img" t-value="any(product.mapped('product_variant_ids.image_variant'))"/>
  <t t-set="image_ids" t-value="product.product_image_ids"/>
  <div id="o-carousel-product" class="carousel slide" data-ride="carousel" data-interval="0">
    <div class="carousel-outer">
      <div class="carousel-inner">
        <div t-if="variant_img" class="item active" itemprop="image" t-field="product.product_variant_id.image" t-options="{'widget': 'image', 'class': 'product_detail_img js_variant_img', 'alt-field': 'name', 'zoom': 'image', 'unique': product['__last_update'] + (product.product_variant_id['__last_update'] or '')}"/>
    <ol class="carousel-indicators" t-if="len(image_ids) or variant_img">
      <li data-target="#o-carousel-product" t-att-data-slide-to="1 if variant_img else 0" t-att-class="'' if variant_img else 'active'">
        <img class="img img-responsive" t-attf-src="/website/image/product.template/{{product.id}}/image/90x90" t-att-alt="product.name"/>
      </li>
      <t t-if="len(image_ids)" t-foreach="image_ids" t-as="pimg">
        <li data-target="#o-carousel-product" t-att-data-slide-to="pimg_index + (variant_img and 2 or 1)">
          <img class="img img-responsive" t-attf-src="/website/image/product.image/{{pimg.id}}/image/90x90" t-att-alt="pimg.name"/>
        </li>
      </t>
    </ol>
  </div>
</t>
<script language="javascript" type="text/javascript">

    <MY SCRIPT>

</script>

inside the 'script' tag i need to read one of the qweb variable, I need the {{product.id}}, to load a dinamic path in javascript. 在'script'标记内,我需要读取qweb变量之一,我需要{{product.id}},才能在javascript中加载动态路径。

I've tryied a lot of variants: 我尝试了很多变体:

var WRProdId ="{{product.id}}";

also: 也:

<input type="hidden" id="Current360Product" name="Current360Product" value="{{product.id }}"/> 

<script language="javascript" type="text/javascript"> 
var WRProdId = document.getElementById("Current360Product").value;

but the {{product.id}} is never interpreted 但是{{product.id}}从未被解释

How can I read it? 我该怎么读?

解决方案是:

var WRProdId = <t t-esc="product.id"/>;

解决方案是:

var WRProdId = "<t t-esc="product.id"/>";

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

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