创建客户端动作¶
客户端动作会触发一个完全在客户端实现的动作。使用客户端动作的一个好处是能够轻松创建高度自定义的界面。客户端动作通常由 OWL 组件定义;我们也可以使用 web 框架,并使用服务、核心组件、钩子等。
创建 客户端动作,不要忘记使其可访问。
<record model="ir.actions.client" id="my_client_action"> <field name="name">My Client Action</field> <field name="tag">my_module.MyClientAction</field> </record>
创建一个表示客户端动作的组件。
my_client_action.js
¶import { registry } from "@web/core/registry"; import { Component } from "@odoo/owl"; class MyClientAction extends Component {} MyClientAction.template = "my_module.clientaction"; // remember the tag name we put in the first step registry.category("actions").add("my_module.MyClientAction", MyClientAction);
my_client_action.xml
¶<?xml version="1.0" encoding="UTF-8" ?> <templates xml:space="preserve"> <t t-name="awesome_tshirt.clientaction"> Hello world </t> </templates>