我已创建自定义模块以在网站
中显示日历My In JS无法调用require()。
我的代码
website_calendar_block.js
odoo.define('website_calendar_block', function(require) { "use strict";
var website = require('website.website');
alert(website);
});
website_calendar_templates.xml
<template id="website_calendar_assets_frontend" inherit_id="website.assets_frontend" name="Calendar block assets">
<xpath expr="/t" position="inside">
<script type="text/javascript" src="/website_calendar/static/src/js/website_calendar_block.js"></script>
</xpath> </template>
<div class="calendar"> <span class="fa fa-2x fa-calendar"/></div>
我的问题是在加载网站页面时收到警报未定义在警报(网站);
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
这是website.assets_fronted:
<template id="assets_frontend" inherit_id="web.assets_frontend" name="Website Frontend Assets">
<xpath expr="//link[last()]" position="after">
<link rel="stylesheet" type="text/less" href="/website/static/src/less/website.ui.less"/>
<link rel="stylesheet" type="text/less" href="/website/static/src/less/website.ui.components.less"/>
<link rel="stylesheet" type="text/less" href="/website/static/src/less/website.wrapwrap.less"/>
<link rel="stylesheet" type="text/less" href="/website/static/src/less/website.snippets.less"/>
<link rel="stylesheet" type="text/css" href="/website/static/src/less/website.zoomodoo.less"/>
</xpath>
<xpath expr="//script[last()]" position="after">
<script type="text/javascript" src="/website/static/src/js/website.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.share.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.snippets.animation.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.zoomodoo.js"></script>
</xpath>
</template>
如何使用xpath找到t元素? 如果它没有抛出错误,它必定已找到其他内容,因此在网站资产被加载之前可能会调用您的Javascript代码。
为什么不在website.assets_frontend中使用<xpath expr="//script[last()]" position="after">
?