这是我的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', [[]])
    }
})

最佳答案

改成这个

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...

关于javascript - ReferenceError:实例未定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47707404/

10-08 23:09