如何在js Odoo 15中调用超级函数



我需要澄清JS中的_super。我试图继承一个小部件并调用一个超级方法。我尝试了一种不同的方式来实现这个功能。只有一种方法奏效了。但是当分析Odoo源代码时,我们可以看到其他方法用于监督一个方法。我需要知道为什么奥多奥在不同的时间使用不同的超级方法。

这是我的示例代码:

*.js

odoo.define('pos_session_route.payment', function (require) {
"use strict";
var account_payment = require('account.payment');
var AbstractField = require('web.AbstractField');
var core = require('web.core');
var field_registry = require('web.field_registry');
var QWeb = core.qweb;
var _t = core._t;
console.log('paymenyyyyy',account_payment);
account_payment.ShowPaymentLineWidget.include({
//        AbstractField.include({
payment_widget : function () {
console.log('paymenyyyyy');
},
_render:function(){
console.log('hihooo');
// account_payment.prototype._super.apply(this.arguments); didn't work
// account_payment.ShowPaymentLineWidget.prototype._super.apply(this.arguments); didn't work
// this._super.apply(this, arguments);didn't work
this._super(this.arguments); it works
}
})

});

在Odoo 15中,AbstractField是猫头鹰组件。

有了猫头鹰组件,你最好用super(...arguments);称之为超级

对于非猫头鹰组件,您可以使用this._super.apply(this, arguments);调用super

此外,在阅读您的代码时,我建议您将在AbstractFieldaccount_payment中执行的操作分开。但这不关我的事,你可以有你这样做的理由^^

希望它能有所帮助!