如何覆盖 Odoo 11 中的 JS 变量?
How to override a JS variable in Odoo 11?
考虑以下 class 存在
local.MyWidget = instance.Widget.extend({
events: {
"click .my_button": "button_clicked",
},
button_clicked: function() {
console.log("Button Clicked");
}
});
我想像下面这样向变量添加一个事件
MyWidget.include({
events: {
"click .new_button": "new_button_clicked",
},
new_button_clicked: function() {
console.log("New Button Clicked.");
}
});
上面的方法不起作用,我得到的错误是
events is undefined
在 odoo 中如何做到这一点?
你也可以这样做:
MyWidget.include({
init: function(parent, options) {
this.events["click .new_button"] = "new_button_clicked";
this._super(parent, options);
},
new_button_clicked: function() {
console.log("New Button Clicked.");
}
});
考虑以下 class 存在
local.MyWidget = instance.Widget.extend({
events: {
"click .my_button": "button_clicked",
},
button_clicked: function() {
console.log("Button Clicked");
}
});
我想像下面这样向变量添加一个事件
MyWidget.include({
events: {
"click .new_button": "new_button_clicked",
},
new_button_clicked: function() {
console.log("New Button Clicked.");
}
});
上面的方法不起作用,我得到的错误是
events is undefined
在 odoo 中如何做到这一点?
你也可以这样做:
MyWidget.include({
init: function(parent, options) {
this.events["click .new_button"] = "new_button_clicked";
this._super(parent, options);
},
new_button_clicked: function() {
console.log("New Button Clicked.");
}
});