我是初学者,我在odoo10.0上编写java脚本代码。我提到了编写以前版本的代码。所以,我想在我的主页加载时打印'Nidhin,你的宠物商店主页加载'。
In mypetstore/static/src/js/my_pet_store.js:
mypetstore是我的模块名称。
odoo.define('mypetstore.my_pet_store', function (require) {
"use strict";
var Class = require('web.Class');
var Widget = require('web.Widget');
var core = require('web.core');
var utils = require('web.utils');
var _t = core._t;
var _lt = core._lt;
var QWeb = core.qweb;
console.log("Nidhin");
HomePage = Widget.extend({
start: function() {
console.log("Nidhin, your pet store home page loaded");
},
});
core.view_registry.add('my_pet_store', HomePage);
});
在mypetstore / views / my_pet_store.xml
中<template id="assets_backend" name="petstore"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/mypetstore/static/src/js/my_pet_store.js"></script>
</xpath>
</template>
<record id="action_home_page_my_petstore" model="ir.actions.client">
<field name="name">Pet Store Home</field>
<field name="tag">my_pet_store</field>
</record>
在菜单中:
<menuitem id="home_page_my_petstore_menu"
name="Home Page"
parent="my_petstore_menu"
action="action_home_page_my_petstore"/>
在custom_addons / mypetstore / manifest.py中:
'取决于':[ “网络”, ] '数据':[ '视图/ my_pet_store.xml', '视图/ menu.xml文件', ] 'demo':[ ],
预期行为:
我在openerp(先前版本)中看到了相同的代码:
openerp.oepetstore = function(instance, local) {
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
local.HomePage = instance.Widget.extend({
start: function() {
console.log("pet store home page loaded");
},
});
instance.web.client_actions.add('petstore.homepage',
'instance.oepetstore.HomePage');
}
所以,我想在我的主页加载时打印'Nidhin,你的宠物商店主页加载'。
答案 0 :(得分:0)
odoo.define('zbtoken.hellojs', 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",
start: function() {
console.log("Hello JS");
},
});
core.action_registry.add('HelloJS', HomePage);
});
In .xml file :
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="HelloJS">
<div> </div>
</t>
</templates>
In .xml view file:
You have to specify your js file in view's xml file like:
<data>
<template id="assets_backend" name="petstore"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="your js file path">
</script>
</xpath>
</template>
<record id="map_id" model="ir.actions.client">
<field name="name">HelloJS</field>
<field name="tag">HelloJS</field>
</record>
</data>
in _maniifest_.py
'data': [
'views/your_xml_file',
],
'demo': [
],
'qweb': ['static/src/xml/your_xml_file'],
拨打id&#39; map_id&#39;在菜单中,您将获得打印&#39; Hello JS&#39;在控制台。对不起,迟到的回复。