我想在odoo中创建一个新的js文件。
此文件适用于在 TreeView 中创建的按钮。此 TreeView 以 XML 文件形式提供。为此,我在 static 文件夹中创建了一个 js 文件。但我不知道这个按钮如何调用js文件的函数。 什么是web.core?如果我想访问odoo中的模型如何访问这个模型?
最佳答案
您可以通过在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
},
});
});
像这样,您可以扩展 TreeView 并在js文件中添加按钮代码。
关于odoo 12 中的 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59559272/