【问题标题】:JavaScript in odoo 12odoo 12 中的 JavaScript
【发布时间】:2020-01-02 15:43:39
【问题描述】:

我想在odoo中创建一个新的js文件。

此文件适用于在树视图中创建的按钮。此树视图在 XML 文件中可用。为此,我在静态文件夹中创建了一个 js 文件。但是不知道js文件的这个按钮调用函数是怎么实现的。 web.core 是什么?如果我想在 odoo 中访问模型,如何访问这个模型?

【问题讨论】:

    标签: javascript button odoo


    【解决方案1】:

    您可以通过在 js 文件中定义事件来调用函数。 例如,这里我正在访问 chatterbox

    odoo.define('yourmodule.js script', function (require) {
    "use strict";
    
    var attchment_box = require('mail.AttachmentBox');
    var core = require('web.core');
    
    var QWeb = core.qweb;
    
    attchment_box.include({
    events: _.extend({}, attchment_box.prototype.events, {
        "click .your button class or # button id": "your method name",
    
    }),
    init: function () {
    
        this._super.apply(this, arguments);
    
    },
    start: function() {
    
        this._super.apply(this, arguments);
    },
    
    
    your method: function (ev) {
        //Your button code
     },
    });
    
    });
    

    这样,你可以在js文件中扩展树形视图并添加按钮代码。

    【讨论】:

      猜你喜欢
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 2019-03-21
      相关资源
      最近更新 更多