【问题标题】:call_button() missing 1 required positional argument: 'method' odoocall_button() 缺少 1 个必需的位置参数:“方法”odoo
【发布时间】:2019-06-15 03:54:01
【问题描述】:

我试图在单击按钮时调用 js 函数,但我得到 call_button() 缺少 1 个必需的位置参数:“方法”错误。

对于包含我的点击按钮功能的 location_tracker.js

odoo.define('location_tracker.location_tracker', function (require) {
"use strict";

var FormController = require('web.FormController');

FormController.include({
    _onButtonClicked: function (event) {
           if(event.data.attrs.id === "set_location"){
             alert("OK");
           }
           this._super(event);
        }
    });
});

对于具有名称字段和设置位置按钮的 view.xml

<record id="location_tracker_form_view" model="ir.ui.view">
        <field name="name">location.tracker.form.view</field>
        <field name="model">location_tracker</field>
        <field name="arch" type="xml">
            <form>
               <header>
                   <button id="set_location" type="object" 
                     string="SetLocation"/>
               </header>
                <sheet>
                     <group>
                        <field name="name"/>
                        <field name="latitude"/>
                        <field name="longitude"/>
                     </group>
                </sheet>
            </form>
        </field>
</record>

<template id="assets_backend" name="location_tracker assets" 
       inherit_id="web.assets_backend">
    <xpath expr="." position="inside">
        <script type="text/javascript" 
         src="/location_tracker/static/src/js/location_tracker.js"> 
       </script>
    </xpath>
</template>

对于我的模型的 model.py

from odoo import models, fields, api
class LocationTracker(models.Model):

  _name = 'location_tracker'
  name = fields.Char(string="Notes")
  location_tracker_id = fields.Char(string="Id")
  latitude = fields.Float(string="Latitude", digits=(16,7), 
   readonly=True)
  longitude = fields.Float(string="Longitude", digits=(16,7), 
 readonly=True)

def set_location(self):
   print ('Called')

【问题讨论】:

    标签: javascript python odoo


    【解决方案1】:

    您需要在button中添加一个name attr,并设置方法名存在于python文件中。

    <button 
        id="set_location" 
        type="object"
        name="set_location"
        string="SetLocation"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 2019-10-10
      • 2017-03-27
      • 2019-11-12
      • 2019-12-23
      相关资源
      最近更新 更多