这是我的XML代码。当我单击按钮时,它显示以下错误:
ReferenceError:未定义实例
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_add" t-operation="after">
<t t-if="widget.model=='ref.reference'">
<button class="btn btn-sm btn-default" type="button">Enable</button>
<button class="btn btn-sm btn-primary disable_ref" type="button">Disable</button>
</t>
</t>
</t>
</templates>
这是javascript在这段代码中有什么问题:
var ListView = require('web.ListView');
ListView.include({
render_buttons: function() {
// GET BUTTON REFERENCE
this._super.apply(this, arguments)
if (this.$buttons) {
var btn = this.$buttons.find('.disable_ref')
}
// PERFORM THE ACTION
btn.on('click', this.proxy('do_new_button'))
},
do_new_button: function() {
instance.web.Model('ref.reference')
.call('ref_dis', [[]])
}
})
答案 0 :(得分:0)
将其更改为此
JS
odoo.define('reference.js', function(require) {
'use strict';
var ListView = require('web.ListView')
var Model = require('web.Model')
ListView.include({
render_buttons: function() {
this._super.apply(this, arguments)
if (this.$buttons) {
this.$buttons.find('.disable_ref').on('click', this.proxy('do_new_button'))
}
},
do_new_button: function () {
var model = new Model('ref.reference')
model.call('ref_dis', [[]]);
}
})
})
模型
from odoo import fields, models, api
class ReferenceSource(models.Model):
_name = "ref.reference"
@api.model
def ref_dis(self):
some logic...