Odoo10 Javascript Widget操作不起作用:ClientWidget不是函数 [英] Odoo10 Javascript Widget action not working: ClientWidget is not a function
问题描述
我仍在学习如何正确添加自己的JavaScript代码.我正在尝试将自己的内容添加到Odoo后端.
I'm still learning how to properly add your own javascript code. I'm trying to add my own stuff into Odoo backend.
我正在仔细阅读建筑接口扩展"指南( https://www.odoo.com/documentation/10.0/howtos/web.html ),但是以太严重不准确或完全过时.
I was carefully reading "Building Interface Extensions" guide (https://www.odoo.com/documentation/10.0/howtos/web.html), but it is ether badly inaccurate or completely outdated.
在查看了诸如帐户,项目,CRM之类的Odoo官方模块之后,我编写了如下代码:
After looking at Odoo official modules like Account, Project, CRM I've coded something like this:
odoo.define('rhp.main', function (require) {
"use strict";
var core = require('web.core');
var _t = core._t;
var _lt = core._lt;
var Widget = require('web.Widget');
var QWeb = core.qweb;
var Explorer = Widget.extend({
init: function(parent, options) {
console.log('Explorer inited');
},
start: function() {
console.log('Explorer started');
},
});
/* NONE OF THESE WORK OK */
//core.view_registry.add('exploreraction', Explorer);
//core.action_registry.add('exploreraction', function() { return new Explorer(); });
core.action_registry.add('exploreraction', 'rhp.main.Explorer');
//odoo.client_actions.add('exploreraction', Explorer);
/* "Main loaded" is successfully printed in console */
console.log("Main loaded");
return {
Explorer: Explorer,
};
});
我的模块xml数据:
<record id="explorer_action" model="ir.actions.client">
<field name="name">Document Explorer</field>
<field name="tag">exploreraction</field>
<field name="target">main</field>
</record>
<menuitem name="Documents" id="main_docs" />
<menuitem name="Document Explorer" id="rhp_explorer" parent="rhp.main_docs" action="rhp.explorer_action"/>
这是我的最新代码,当我单击菜单项时,什么也没有发生,并且出现此弹出错误:
This is my latest code and when I click the menu item nothing happens and I get this popup error:
TypeError: ClientWidget is not a function
此处粘贴的跟踪 https://pastebin.com/QLCaLwHC
======================================
=========================================
我添加了模板,就像Vishal Khichadiya的示例一样:
I added the template, like in Vishal Khichadiya's example:
<t t-name="exploreraction" >
<div id="exploreraction_div">
test
</div>
</t>
现在以这种方式添加了动作:
Action is now added this way:
core.action_registry.add('exploreraction', Explorer);
现在,当我导航至菜单项时,我会收到此错误:
Now when I navigate to my menu item I'm now getting this error:
TypeError: this.__getterSetterInternalMap is undefined
此处的新追溯: https://pastebin.com/phrqXFkz
推荐答案
我也是Odoo和JS的新手,我尝试了一些东西,如下所示:
I'm also new to Odoo and JS, and I have tried something and that is given below:
In your /static/src/js/your_.js file, add the code:
odoo.define('zbtoken.map', function (require) {
"use strict";
var Widget = require('web.Widget');
var core = require('web.core');
var utils = require('web.utils');
var HomePage = Widget.extend({
template: "HelloJS",
init: function(parent) {
this._super(parent);
console.log("Hello JS, I'm inside of init.");
},
start: function() {
console.log("Hello JS, I'm inside of start.");
},
});
core.action_registry.add('HelloJS', HomePage);
return HomePage;
});
在您的/static/src/xml/your_.xml文件中:
In your /static/src/xml/your_.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="HelloJS">
<div> </div>
</t>
</templates>
在您的/views/your_.xml文件中:
In your /views/your_.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<template id="assets_backend" name="petstore"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/your_module_name/static/src/js/your_js_file.js">
</script>
</xpath>
</template>
<record id="hellojs_id" model="ir.actions.client">
<field name="name">HelloJS</field>
<field name="tag">HelloJS</field>
</record>
<menuitem id="hellojs_menu"
name="HelloJS"
action="hellojs_id"/>
</data>
</odoo>
在清单 .py中:
'data': [
'views/your_.xml file',
],
'qweb': ['static/src/xml/your_.xml file'],
它将起作用.请尝试.
这篇关于Odoo10 Javascript Widget操作不起作用:ClientWidget不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!