在树视图odoo中显示html
Display html in tree view odoo
是否可以在树视图中显示 html?
例如将 strong 添加到字符串 MY STRING
我正在尝试使用 widget="html" 但 strong 标签是可见的!
.py
@api.depends('name')
def _get_html(self):
self.html_text = "<strong>" + str(self.name) + "</strong>"
html_text = fields.Char(compute='_get_html')
.xml
<field name="html_text"/>
要在列表视图中启用 HTML,您需要重写方法 _format(),如下所示。(对于 Odoo v10)
JS
odoo.define('html_in_tree_field.web_ext', function (require) {
"use strict";
var Listview = require('web.ListView');
var formats = require('web.formats');
Listview.Column.include({
_format: function (row_data, options) {
// Removed _.escape() function to display html content.
// Before : return _.escape(formats.format_value(row_data[this.id].value, this, options.value_if_empty));
return formats.format_value(row_data[this.id].value, this, options.value_if_empty);
}
});
});
XML在上面添加JS.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_ext" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/html_in_tree_field/static/src/js/web_ext.js"></script>
</xpath>
</template>
</odoo>
__manifest__.py
{
...
...
'data': [
...
'views/above_xml_filename.xml',
],
....
}
是否可以在树视图中显示 html?
例如将 strong 添加到字符串 MY STRING
我正在尝试使用 widget="html" 但 strong 标签是可见的!
.py
@api.depends('name')
def _get_html(self):
self.html_text = "<strong>" + str(self.name) + "</strong>"
html_text = fields.Char(compute='_get_html')
.xml
<field name="html_text"/>
要在列表视图中启用 HTML,您需要重写方法 _format(),如下所示。(对于 Odoo v10)
JS
odoo.define('html_in_tree_field.web_ext', function (require) {
"use strict";
var Listview = require('web.ListView');
var formats = require('web.formats');
Listview.Column.include({
_format: function (row_data, options) {
// Removed _.escape() function to display html content.
// Before : return _.escape(formats.format_value(row_data[this.id].value, this, options.value_if_empty));
return formats.format_value(row_data[this.id].value, this, options.value_if_empty);
}
});
});
XML在上面添加JS.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_ext" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/html_in_tree_field/static/src/js/web_ext.js"></script>
</xpath>
</template>
</odoo>
__manifest__.py
{
...
...
'data': [
...
'views/above_xml_filename.xml',
],
....
}