我已经成功继承了project.portal_my_project模板,并添加了一个带有点击处理程序的div。
<template id="portal_project_inherit" name="portal_project_inherit" inherit_id="project.portal_my_project">
<xpath expr="t" position="inside">
<div class="o_portal_project_custom_block mt-3" >
<div t-on-click.stop="() => this._onClickTest()"><p>TEST</p></div>
</div>
</xpath>
</template>
如何将此点击链接到 JavaScript 函数?我尝试跟随但没有成功。
import { Dialog } from '@web/core/dialog/dialog';
import { patch } from '@web/core/utils/patch';
import { useService } from '@web/core/utils/hooks';
const { Component, useSubEnv, useState } = owl;
export class ImageViewer extends Component {
setup() {
super.setup();
}
//----------
// Handlers
//----------
_onClickTest() {
console.log("test")
throw new Error("TEEEEEEEEST");
}
}
ImageViewer.template = 'test.portal_project_inherit';
<template id="portal_project_inherit" name="portal_project_inherit" inherit_id="project.portal_my_project">
<xpath expr="t" position="inside">
<div class="o_portal_project_custom_block mt-3" >
<div id="test_click"><p>TEST</p></div>
</div>
</xpath>
</template>
JS
/** @odoo-module **/
import publicWidget from "@web/legacy/js/public/public_widget";
publicWidget.registry.WebsiteSaleLayout = publicWidget.Widget.extend({
selector: '.o_portal_project_custom_block',
events: {
'click #test_click': '_onClickTest',
},
_onClickTest() {
console.log("test")
throw new Error("TEEEEEEEEST");
},
})