gpt4 book ai didi

javascript - 仅对自定义模块或 View 应用 JS 自定义 - Odoo

转载 作者:行者123 更新时间:2023-11-28 05:04:13 24 4
gpt4 key购买 nike

我想在我的自定义模块中自定义 ListView 填充,所以我按如下方式进行:

my_custom_module.js:

odoo.define('my_custom_module', function(require){
'use strict';
var core = require('web.core');
var List = core.view_registry.get('list');
var QWeb = core.qweb;
List.List.include({
render: function () {
var self = this;
this.$current.html(
QWeb.render('ListView.rows', _.extend({}, this, {
render_cell: function () {
return self.render_cell.apply(self, arguments); }
})));
this.pad_table_to(1);
},
});
});

在我的 XML 中:

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="assets_backend" name="my_custom_module assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script src="/my_custom_module/static/src/js/my_custom_module.js" type="text/javascript" />
</xpath>
</template>
</odoo>

但问题是这适用于我所有的 Odoo 模块!

如何指定自定义仅适用于我的 my_custom_module ?

感谢您的帮助:)

最佳答案

通过使用 List.List.include({ ...),您可以扩展 List 小部件的现有功能。您所要做的就是 create your own widget 扩展 List 并将其分配给您的查看

如果您不想并且想继续使用已有的方法,您可以在 View 中插入一个元素,该元素将用作 Hook ,您可以将其用作 Hook ,以便您可以应用更改仅以您的意见为准。例如,在 View 中插入一个元素:

<div style="visibility: hidden" id="my_view" />

然后在你的 JavaScript 中:

if ($( "#my_view" ).length) {

// your element exists, that means the javascript code runs on your view and your custom code should be executed.

} else {

// another list is being rendered and you should not run any custom code.
}

关于javascript - 仅对自定义模块或 View 应用 JS 自定义 - Odoo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41875922/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com