JavaScript in odoo 12



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

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

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

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 文件中添加按钮代码。

最新更新