Odoo javascript onclick事件 [英] Odoo javascript onclick event
问题描述
是否可以创建我自己的按钮,这个按钮点击调用javascript函数?像简单的onclick javascript方法一样?
Is it possible create my own button and this button click call javascript function? Like simple onclick javascript method?
如果答案是肯定的,我该怎么做?
If the answer is yes, how can I do that?
我想要使用添加项目按钮或创建我自己的按钮,调用相同的功能,如我点击添加项目按钮。
I want to use "Add an item" button or create my own button that calls the same function like I click on "Add an item" button.
推荐答案
首先创建按钮,您想要进行一些修改。
First Create button where ever you want to create with some modifications.
<button string="Click" custom="click"/>
然后创建一个包含以下代码的JS文件。
Then create one JS file that will contain following code.
odoo.define('YOUR_MODULE.FILENAME', function (require) {
"use strict";
var form_widget = require('web.form_widgets');
var core = require('web.core');
var _t = core._t;
var QWeb = core.qweb;
form_widget.WidgetButton.include({
on_click: function() {
if(this.node.attrs.custom === "click"){
// YOUR CODE
return;
}
this._super();
},
});
});
我提出了这类问题,我得到了这个解决方案这个答案部分工作。请参考此链接如何为formview编写事件里面的标题按钮? odoo 10
i have posed this type of question, i got this solution this answer working partially. please refer this link how to write events for formview inside header buttons? odoo 10
这篇关于Odoo javascript onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!