Odoo10 Javascript 小部件操作不起作用:ClientWidget 不是函数
Odoo10 Javascript Widget action not working: ClientWidget is not a function
我仍在学习如何正确添加您自己的 javascript 代码。我正在尝试将我自己的东西添加到 Odoo 后端。
我仔细阅读了 "Building Interface Extensions" 指南 (https://www.odoo.com/documentation/10.0/howtos/web.html),但它非常不准确或完全过时。
在查看了账户、项目、CRM 等 Odoo 官方模块后,我编写了如下代码:
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"/>
这是我的最新代码,当我点击菜单项时没有任何反应,我得到了这个弹出错误:
TypeError: ClientWidget is not a function
此处粘贴回溯https://pastebin.com/QLCaLwHC
=========================================
编辑:
我添加了模板,就像 Vishal Khichadiya 的示例一样:
<t t-name="exploreraction" >
<div id="exploreraction_div">
test
</div>
</t>
现在以这种方式添加动作:
core.action_registry.add('exploreraction', Explorer);
现在,当我导航到我的菜单项时,出现此错误:
TypeError: this.__getterSetterInternalMap is undefined
这里有新的回溯:https://pastebin.com/phrqXFkz
您需要自己设计模板。
您将在 odoo 中找到创建模板的参考代码。
将您的模板文件添加到清单文件中 'qweb':["static/src/xml/my_template.xml"]
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');
},
});
//exploreraction is must be your template name
core.action_registry.add('exploreraction', Explorer);
return Explorer;
});
示例模板代码:
<t t-name="exploreraction" >
<div id="my_temp_id">
<div class="ex_button">
<div class="cancle_btn">
<button class="btn btn-danger">Cancle</button>
</div>
<div class="Add_btn">
<button class="btn btn-success">Add </button>
</div>
</div>
</div>
</t>
使用您的其他 xml 个文件创建 assets_backend.xml。
/view/assets_backend.xml
--> 这里需要添加javasscript文件路径。
<?xml version="1.0"?>
<odoo>
<data>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr="script[last()]" position="after">
<script type="text/javascript" src="/static/src/js/rhp_main.js"></script>
</xpath>
</template>
<template id="assets_common" inherit_id="web.assets_common">
<xpath expr="script[last()]" position="after">
</xpath>
</template>
</data>
</odoo>
我也是 Odoo 和 JS 的新手,我尝试了一些东西,如下所示:
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 文件中:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="HelloJS">
<div> </div>
</t>
</templates>
在您的 /views/your_.xml 文件中:
<?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'],
它会起作用的。请尝试一下。
我不熟悉Bounty and I have solution for this link_to_the_screenshot_of_desired_output。它将正常工作。
Create your js file in /module_name/static/src/js/your_js_file.js and
add the following code :
odoo.define('mypetstore.test_js', function (require) {
"use strict";
var Widget = require('web.Widget');
var core = require('web.core');
var Model = require('web.Model');
var ProductsWidget = Widget.extend({
template: "ProductsWidget",
init: function(parent, products, color) {
this._super(parent);
this.products = products;
this.color = color;
},
});
var HomePage = Widget.extend({
start: function() {
var products = new ProductsWidget(
this, ["cpu", "mouse", "keyboard", "graphic card",
"screen"], "#00FF00");
products.appendTo(this.$el);
},
});
core.action_registry.add('ProductsWidget', HomePage);
});
在 /module_name/static/src/xml/your_xml_file.xml 中创建您的 xml 文件并添加以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="ProductsWidget">
<div>
<t t-foreach="widget.products" t-as="product">
<span class="oe_products_item"
t-attf-style="background-color: {{ widget.color
}};">
<t t-esc="product"/>
</span>
<br/>
</t>
</div>
</t>
</templates>
在 /module_name/static/src/css/your_css_file.css 中创建您的 css 文件并添加以下代码:
.oe_products_item {
display: inline-block;
padding: 3px;
margin: 5px;
border: 1px solid black;
border-radius: 3px;
}
在 /module_name/views/your_xml_file_.xml 中创建视图的 xml 文件并添加以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<template id="assets_backend" name="give_name"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/module_name/static/src/js/your_js_file_name.js">
</script>
<link href="/module_name/static/src/css/your_css_file.css"
rel="stylesheet"></link>
</xpath>
</template>
<record id="template_id" model="ir.actions.client">
<field name="name">ProductsWidget</field>
<field name="tag">ProductsWidget</field>
</record>
<menuitem id="home_page_menu"
name="Home Page"
action="template_id"/>
</data>
</odoo>
在manifest.py中添加如下代码:
'data': [
'views/your_xml_file.xml',
],
'qweb': ['static/src/xml/pet.xml'],
我仍在学习如何正确添加您自己的 javascript 代码。我正在尝试将我自己的东西添加到 Odoo 后端。
我仔细阅读了 "Building Interface Extensions" 指南 (https://www.odoo.com/documentation/10.0/howtos/web.html),但它非常不准确或完全过时。
在查看了账户、项目、CRM 等 Odoo 官方模块后,我编写了如下代码:
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"/>
这是我的最新代码,当我点击菜单项时没有任何反应,我得到了这个弹出错误:
TypeError: ClientWidget is not a function
此处粘贴回溯https://pastebin.com/QLCaLwHC
=========================================
编辑:
我添加了模板,就像 Vishal Khichadiya 的示例一样:
<t t-name="exploreraction" >
<div id="exploreraction_div">
test
</div>
</t>
现在以这种方式添加动作:
core.action_registry.add('exploreraction', Explorer);
现在,当我导航到我的菜单项时,出现此错误:
TypeError: this.__getterSetterInternalMap is undefined
这里有新的回溯:https://pastebin.com/phrqXFkz
您需要自己设计模板。
您将在 odoo 中找到创建模板的参考代码。
将您的模板文件添加到清单文件中 'qweb':["static/src/xml/my_template.xml"]
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');
},
});
//exploreraction is must be your template name
core.action_registry.add('exploreraction', Explorer);
return Explorer;
});
示例模板代码:
<t t-name="exploreraction" >
<div id="my_temp_id">
<div class="ex_button">
<div class="cancle_btn">
<button class="btn btn-danger">Cancle</button>
</div>
<div class="Add_btn">
<button class="btn btn-success">Add </button>
</div>
</div>
</div>
</t>
使用您的其他 xml 个文件创建 assets_backend.xml。
/view/assets_backend.xml --> 这里需要添加javasscript文件路径。
<?xml version="1.0"?>
<odoo>
<data>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr="script[last()]" position="after">
<script type="text/javascript" src="/static/src/js/rhp_main.js"></script>
</xpath>
</template>
<template id="assets_common" inherit_id="web.assets_common">
<xpath expr="script[last()]" position="after">
</xpath>
</template>
</data>
</odoo>
我也是 Odoo 和 JS 的新手,我尝试了一些东西,如下所示:
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 文件中:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="HelloJS">
<div> </div>
</t>
</templates>
在您的 /views/your_.xml 文件中:
<?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'],
它会起作用的。请尝试一下。
我不熟悉Bounty and I have solution for this link_to_the_screenshot_of_desired_output。它将正常工作。
Create your js file in /module_name/static/src/js/your_js_file.js and
add the following code :
odoo.define('mypetstore.test_js', function (require) {
"use strict";
var Widget = require('web.Widget');
var core = require('web.core');
var Model = require('web.Model');
var ProductsWidget = Widget.extend({
template: "ProductsWidget",
init: function(parent, products, color) {
this._super(parent);
this.products = products;
this.color = color;
},
});
var HomePage = Widget.extend({
start: function() {
var products = new ProductsWidget(
this, ["cpu", "mouse", "keyboard", "graphic card",
"screen"], "#00FF00");
products.appendTo(this.$el);
},
});
core.action_registry.add('ProductsWidget', HomePage);
});
在 /module_name/static/src/xml/your_xml_file.xml 中创建您的 xml 文件并添加以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="ProductsWidget">
<div>
<t t-foreach="widget.products" t-as="product">
<span class="oe_products_item"
t-attf-style="background-color: {{ widget.color
}};">
<t t-esc="product"/>
</span>
<br/>
</t>
</div>
</t>
</templates>
在 /module_name/static/src/css/your_css_file.css 中创建您的 css 文件并添加以下代码:
.oe_products_item {
display: inline-block;
padding: 3px;
margin: 5px;
border: 1px solid black;
border-radius: 3px;
}
在 /module_name/views/your_xml_file_.xml 中创建视图的 xml 文件并添加以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<template id="assets_backend" name="give_name"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/module_name/static/src/js/your_js_file_name.js">
</script>
<link href="/module_name/static/src/css/your_css_file.css"
rel="stylesheet"></link>
</xpath>
</template>
<record id="template_id" model="ir.actions.client">
<field name="name">ProductsWidget</field>
<field name="tag">ProductsWidget</field>
</record>
<menuitem id="home_page_menu"
name="Home Page"
action="template_id"/>
</data>
</odoo>
在manifest.py中添加如下代码:
'data': [
'views/your_xml_file.xml',
],
'qweb': ['static/src/xml/pet.xml'],