Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript call_button()缺少1个必需的位置参数:';方法';奥多_Javascript_Python_Odoo - Fatal编程技术网

Javascript call_button()缺少1个必需的位置参数:';方法';奥多

Javascript call_button()缺少1个必需的位置参数:';方法';奥多,javascript,python,odoo,Javascript,Python,Odoo,我试图在单击按钮时调用js函数,但我发现call_button()缺少1个必需的位置参数:“method”错误 用于location_tracker.js,其中包括我的点击按钮功能 odoo.define('location_tracker.location_tracker', function (require) { "use strict"; var FormController = require('web.FormController'); FormController.includ

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

用于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);
        }
    });
});
<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>
用于具有名称字段和设置位置按钮的view.xml

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);
        }
    });
});
<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>

您需要在按钮中添加名称attr,并设置python文件中存在的方法名称

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

您需要在按钮中添加名称attr,并设置python文件中存在的方法名称

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