我在Odoo 9中制作了一个小部件,用于在website view中削减产品描述。将widget="short_desc"添加到产品表单视图和网站产品视图中。我的意思是这样的:
<span t-field="product.description"/> <!-- full description -->
<span t-field="product.description" t-field-options='{"widget": "short_desc"}'/> <!-- short description -->
<span t-field="product.description" widget="short_desc"/> <!-- also tried this syntax -->我找到了一个有用的答案:Odoo 9. How to override form widgets?,但它只在product form中工作,而在website上不起作用。
所以,我有一个widgets.js:
odoo.define('wsup.widgets', function (require) {
'use strict';
var core = require('web.core');
var FieldChar = core.form_widget_registry.get('char');
var ShortDescriptionView = FieldChar.extend({
render_value: function() {
console.log('hey, im working!');
this.$el.html('<span>Ok, widget really works</span>');
},
});
core.form_widget_registry.add('short_desc', ShortDescriptionView);
});当我进入Sales -> Products并打开任何产品时,我可以看到"Ok,小部件真的能工作“而不是它的描述,但是当我进入/shop页面时--产品描述仍然没有变化,JS控制台中什么也没有。
这里是我的网站产品XML视图的一部分(除了简短的描述部分外,它工作得很好):
<div class="product-preview oe_website_sale">
<div class="product-preview__image">
<a t-attf-href="/shop/product/{{ item.id }}">
<span itemprop="image" t-field="item.image" t-field-options='{"widget": "image"}' t-att-alt="item.name"/>
</a>
</div>
<div class="product-preview__info text-center">
<div class="product-preview__info__title">
<h2><a t-attf-href="/shop/product/{{ item.id }}"><span t-field="item.name"/></a></h2>
</div>
<div class="product-preview__info__description">
<p><span t-field="item.description" t-field-options='{"widget": "short_desc"}'/></p>
</div>
</div>
</div>为什么它不能在/shop页面上工作?我忘了做什么?谢谢。
发布于 2016-12-20 11:54:36
正如我所理解的那样,您的要求是显示少量的描述,而不是显示大量的描述。因此,我认为无需创建小部件就可以很容易地实现这一要求。
假设您有以下内容作为描述:
2比1好。
与许多小型耳机不同,苹果耳机的每个耳机都包含两个独立的高性能驱动程序--一个用于处理低音和中档声音的低音喇叭和一个用于高频音频的高音喇叭。这些专用的驱动程序有助于确保整个声波频谱的准确、详细的声音。其结果是:你沉浸在音乐中,听到你从来不知道的细节。即使当你听一个旧的最爱,你可能会觉得你是第一次听到它。
从这大量的描述中,如果你想显示少量的描述或字数,那么你可以简单的使用下面的代码。
<span t-if="product.website_description and len(product.website_description) > 500">
<t t-set="description" t-value="product.website_description[:500] and product.website_description[:500].replace('+', '\n')+'...'"/>
<p class="text-muted ">
<t t-raw="description"/>
</p>
</span>在上面的代码中,:500将是要使用的单词数。
产出将是:
2比1好。
与许多小型耳机不同的是,苹果耳机的每个耳机都包含两个独立的高性能驱动程序--一个到汉的低音炮.
希望这个密码能帮到你。谢谢。
https://stackoverflow.com/questions/41240014
复制相似问题