odoo - 自定义小部件 js 无法识别来自 qweb 的模板
问题描述
我尝试从js 参考测试自定义小部件,但在调试器中出现错误:
错误:QWeb2:找不到模板“some.template”
qweb.xml 已在清单中正确设置,因为当我扩展 ListController 并使用另一个模板时,它可以正常工作。
这是我在 qweb.xml 中使用的模板定义:
<?xml version="1.0" encoding="UTF-8"?>
<template>
<div t-name="some.template">
<span class="val"><t t-esc="widget.count"/></span>
<button>Increment</button>
</div>
</template>
我尝试更改<template>
-> <templates>
,完全删除了标签“模板”,但仍然收到相同的错误消息。
JS:
odoo.define('working.test', function (require) {
var Widget = require('web.Widget');
var Counter = Widget.extend({
template: 'some.template',
events: {
'click button': '_onClick',
},
init: function (parent, value) {
this._super(parent);
this.count = value;
},
_onClick: function () {
this.count++;
this.$('.val').text(this.count);
},
});
// Create the instance
var counter = new Counter(this, 4);
// Render and insert into DOM
counter.appendTo(".o_nocontent_help");
})
显现:
# -*- coding: utf-8 -*-
{
'name': "testwidget",
'summary': """
Short (1 phrase/line) summary of the module's purpose, used as
subtitle on modules listing or apps.openerp.com""",
'description': """
Long description of module's purpose
""",
'author': "My Company",
'website': "http://www.yourcompany.com",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/12.0/odoo/addons/base/data/ir_module_category_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['base'],
'qweb': ['static/qweb.xml'],
# always loaded
'data': [
# 'security/ir.model.access.csv',
'views/views.xml',
'views/web_asset.xml',
],
# only loaded in demonstration mode
'demo': [
'demo/demo.xml',
],
}
知道我需要如何修改此模板以使小部件正常工作以及 db odoo 中的哪个表存储这些模板吗?
解决方案
You can try changing
'qweb': ['static/qweb.xml'],
to
'qweb': ['static/*.xml'],
It happens with me sometimes, by specifying static xml file name, it does not render that template. But by just loading all .xml files by using *, templates are loaded.
推荐阅读
- saxon - 使用 Saxon 9.6 HE 库进行 xslt 转换后,JVM 堆保存内存密集型转换对象
- gremlin - Gremlin - 从属性值的压缩列表中过滤边缘
- python - Python在函数暂停后返回多个变量
- batch-file - 有没有办法将windows服务的pid保存在var中?
- google-app-engine - Vue 生产 URL 重定向在 gae 上返回 404
- java - 这是 Netty 从封闭通道读取的示例吗?
- python - Pandas:转置按列 a 分组的列 (b,c,d) 作为索引
- r - 如何以长格式改变小标题的值
- kotlin - 我可以在没有运行的情况下在 Kotlin 中创建一个可变的函数集合吗?
- javascript - 如何使用“spec”和“mocha-multi-reporters”将失败的测试结果输出到控制台