首页 > 解决方案 > 自定义小部件 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 中的哪个表存储这些模板吗?

标签: odooodoo-12

解决方案


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.


推荐阅读