是否可以在树状视图中显示html?
例如,将strong添加到字符串<强大的>我的STRING< / strong>
我尝试使用widget =“html”,但强标签可见!
的.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"/>
答案 0 :(得分:9)
要在列表视图中启用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);
}
});
});
要在JS上面添加的XML。
<?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>
<强> __清单__。PY 强>
{
...
...
'data': [
...
'views/above_xml_filename.xml',
],
....
}