use*_*doo 7 openerp odoo-9 odoo-10
是否可以在树视图中显示html?
例如,将strong添加到字符串<strong> MY 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')
Run Code Online (Sandbox Code Playgroud)
.XML
<field name="html_text"/>
Run Code Online (Sandbox Code Playgroud)
要在列表视图中启用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);
}
});
});
Run Code Online (Sandbox Code Playgroud)
要在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>
Run Code Online (Sandbox Code Playgroud)
__manifest__.py
{
...
...
'data': [
...
'views/above_xml_filename.xml',
],
....
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2269 次 |
最近记录: |