Javascript call_button()缺少1个必需的位置参数:';方法';奥多
我试图在单击按钮时调用js函数,但我发现call_button()缺少1个必需的位置参数:“method”错误 用于location_tracker.js,其中包括我的点击按钮功能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
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"/>