首先OWL是Odoo14版本新加的功能。

因为是新加的所以并没有太多的说明文档,包括英文板文档也没有;所以你要用它再没有更详细的文档之前你得自己去看源码。

注意owl是没有do_action函数给你跳转至其他视图的。你如果要你的控件可以跳转视图的话就得用“web.AbstractField”去实现了。

owl如何访问记录res_id(或者其他记录信息):

1 this.record.res_id

owl例子:

 1 odoo.define('my_company_users_widget', function (require) {
2 "use strict";
3
4 const { Component } = owl;
5 const AbstractField = require('web.AbstractFieldOwl');
6 const fieldRegistry = require('web.field_registry_owl');
7
8 //这里生成子控件
9 class UserCardInfo extends Component {
10 static template = 'UserCardInfo';
11 CardClicked() {
12 this.trigger('card-clicked', {user_id: this.props.user_id});
13 }
14 }
15
16 class FieldCompanyUser extends AbstractField {
17 static supportedFieldTypes = ['many2many'];
18 static template = 'OWLFieldCompanyUsers';
19 static components = { UserCardInfo };//子控件声明,这样你就可以在界面上使用了
20 constructor(...args) {
21 super(...args);
22 this.data_users = [];
23 }
24 async willStart() {
25 self = this
26 //
27 //
28 await this.rpc({
29 model: 'res.groups',
30 method: 'get_company_users',
31 args: [[self.record.res_id],self.record.res_id]
32 }).then(function (result){
33 self.data_users = result
34 });
35 }
36 UserCardClicked(ev) {
37 console.log(ev.detail.user_id);
38 self = this;
39 this.rpc({//不知道怎么用rpc40 model: 'res.users',
41 method: 'get_userform_action',
42 args: [[ev.detail.user_id]]
43 }).then(function (result){
44 self.action = result;
45 });
46 console.log(self.action);
47
48 //owl是没有do_action函数给你跳转至其他视图的
49 // this.do_action({
50 // name: 'User Info',
51 // type: 'ir.actions.act_window',
52 // res_model: 'res.users',
53 // view_mode: 'form',
54 // view_type: 'form',
55 // views:[false, 'form'],
56 // target: 'current',
57 // res_id: ev.detail.user_id,
58 // flags: {'form': {'action_buttons': true, 'options': {'mode': 'edit'}}},
59 // context: {}
60 // });
61 }
62 }
63
64 fieldRegistry.add('company_users', FieldCompanyUser);
65
66 return {
67 FieldCompanyUser: FieldCompanyUser,
68 };
69 });

以下是template代码

 1 <?xml version="1.0" encoding="UTF-8"?>
2 <templates>
3 <t t-name="UserCardInfo" owl="1">
4 <div class="card mt16" >
5 <div class="card-body" t-on-click="CardClicked" >
6 <h5 class="card-title mt8">
7 <t t-esc="props.user_name"/>
8 </h5>
9 </div>
10 </div>
11 </t>
12
13 <div t-name="OWLFieldCompanyUsers" owl="1" t-on-card-clicked="UserCardClicked">
14 <div class="row ml16 mr16" >
15 <t t-foreach="data_users" t-as="itemUser">
16 <UserCardInfo user_name="itemUser['name']" user_id="itemUser['id']" active='false'/>
17 </t>
18 </div>
19 </div>
20
21 </templates>

Odoo14 OWL 如何访问model方法和res_id的更多相关文章

  1. ASP.NET MVC 5 学习教程:Edit方法和Edit视图详解

    原文 ASP.NET MVC 5 学习教程:Edit方法和Edit视图详解 起飞网 ASP.NET MVC 5 学习教程目录: 添加控制器 添加视图 修改视图和布局页 控制器传递数据给视图 添加模型 ...

  2. 【译】ASP.NET MVC 5 教程 - 7:Edit方法和Edit视图详解

    原文:[译]ASP.NET MVC 5 教程 - 7:Edit方法和Edit视图详解 在本节中,我们继续研究生成的Edit方法和视图.但在研究之前,我们先将 release date 弄得好看一点.打 ...

  3. ThinkPHP的D方法和M方法的区别

    M方法和D方法的区别 ThinkPHP 中M方法和D方法都用于实例化一个模型类,M方法 用于高效实例化一个基础模型类,而 D方法 用于实例化一个用户定义模型类. 使用M方法 如果是如下情况,请考虑使用 ...

  4. Hibernate中evict方法和clear方法说明

    Hibernate中evict方法和clear方法说明 先创建一个对象,然后调用session.save方法,然后调用evict方法把该对象清除出缓存,最后提交事务.结果报错: Exception i ...

  5. Android HTTP实例 使用GET方法和POST方法发送请求

    Android HTTP实例 使用GET方法和POST方法发送请求 Web程序:使用GET和POST方法发送请求 首先利用MyEclispe+Tomcat写好一个Web程序,实现的功能就是提交用户信息 ...

  6. $(document).ready()即$()方法和window.onload方法的比较

    以浏览器装载文档为例,我们都知道在页面完毕后,浏览器会通过JavaScript为DOM元素添加事件.在常规的JavaScript代码中,通常使用window.onload方法,而在jQuery中,使用 ...

  7. wait方法和sleep方法的区别

    一.概念.原理.区别 Java中的多线程是一种抢占式的机制而不是分时机制.线程主要有以下几种状态:可运行,运行,阻塞,死亡.抢占式机制指的是有多个线程处于可运行状态,但是只有一个线程在运行.      ...

  8. M方法和D方法的区别

    M方法和D方法的区别 ThinkPHP 中M方法和D方法都用于实例化一个模型类,M方法 用于高效实例化一个基础模型类,而 D方法 用于实例化一个用户定义模型类. 使用M方法 如果是如下情况,请考虑使用 ...

  9. ThinkPHP 中M方法和D方法详解----转载

    转载的地址,http://blog.163.com/litianyichuanqi@126/blog/static/115979441201223043452383/ 自己学到这里的时候,不能清除的分 ...

随机推荐

  1. Golang:手撸一个支持六种级别的日志库

    Golang标准日志库提供的日志输出方法有Print.Fatal.Panic等,没有常见的Debug.Info.Error等日志级别,用起来不太顺手.这篇文章就来手撸一个自己的日志库,可以记录不同级别 ...

  2. 890. Find and Replace Pattern - LeetCode

    Question 890. Find and Replace Pattern Solution 题目大意:从字符串数组中找到类型匹配的如xyy,xxx 思路: 举例:words = ["ab ...

  3. netty系列之:netty对marshalling的支持

    目录 简介 netty中的marshalling provider Marshalling编码器 Marshalling编码的另外一种实现 总结 简介 在之前的文章中我们讲过了,jboss marsh ...

  4. RabbitMQ 环境安装

    每日一句 Wisdom is knowing what to do next, skill is knowing how to do it, and virtue is doing it. 智慧是知道 ...

  5. 前端 关于请求地址时出现乱码, 出现%E2%80%8B的问题

    做项目时,添加了新的一个接口,习惯性地复制了接口下来.然后测试发现 请求时自动添加 了几个%E2%80%8B这种乱码. 问题原因: 我输出请求地址时也是正确的,是因为复制过来的接口地址会有零宽空格 解 ...

  6. 一个ES设置操作引发的“血案”

    背景说明 ES版本 7.1.4 在ES生产环境中增加字段,一直提示Setting index.mapper.dynamic was removed after version 6.0.0错误.但是我只 ...

  7. dubbo容错机制

    dubbo的容错机制 Failover Cluster(默认) 失败自动切换,当出现失败,重试其它服务器.通常用于读操作,但重试会带来更长延迟. Failfast Cluster 快速失败,只发起一次 ...

  8. Mybatis架构原理(二)-二级缓存源码剖析

    Mybatis架构原理(二)-二级缓存源码剖析 二级缓存构建在一级缓存之上,在收到查询请求时,Mybatis首先会查询二级缓存,若二级缓存没有命中,再去查询一级缓存,一级缓存没有,在查询数据库; 二级 ...

  9. Qt数据可视化(散点图、折线图、柱状图、盒须图、饼状图、雷达图)开发实例

    ​  目录 散点图 折线图 柱状图 水平柱状图 水平堆叠图 水平百分比柱状图 盒须图 饼状图 雷达图 Qt散点图.折线图.柱状图.盒须图.饼状图.雷达图开发实例. 在开发过程中我们会使用多各种各样的图 ...

  10. 用Python做了个图片识别系统(附源码)

    本项目将使用python3去识别图片是否为色情图片,会使用到PIL这个图像处理库,并且编写算法来划分图像的皮肤区域 介绍一下PIL: PIL(Python Image Library)是一种免费的图像 ...