如何在odoo中继承或覆盖js文件? [英] How to inherit or override js file in odoo?

查看:918
本文介绍了如何在odoo中继承或覆盖js文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改js文件中的功能.怎么做?有什么方法可以覆盖该功能吗?

I want to change a function in js file. How to do it? Is there any ways to override the function?

addons/web/static/src/js/views/form_common.js

我要更改function-get_search_result: function(search_val){}

dataset.name_search(search_val, self.build_domain(), 'ilike', 160).done(function(_data) {self._search_create_popup("search", _data);}

需要将值160更改为其他值

预先感谢

推荐答案

关于此问题,这给出了很好的概述.该示例实际上比全局JavaScript更改要深入一些.

There is a good answer/example on this question, which gives a pretty good overview. That example is actually a bit more in depth than necessary for a global JavaScript change.

如果您确定要覆盖的功能,则基本上只需要镜像核心并进行所需的覆盖即可.以下是有关如何更改name_search JavaScript行为的示例概述:

If you identify the function you want to override, then it's mostly just a matter of mirroring core and making the override(s) you want. Here's an example overview of how to change the name_search JavaScript behavior:

...
'data': [
    ...
    'views/assets.xml',
    ...
],
...

your_module/views/assets.xml

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

your_module/static/src/js/custom.js

odoo.define('your_module.custom_feature', function(require) {
"use strict";

Class = require('web.Class');
mixins = require('web.mixins');

var DataSet = Class.extend(mixins.PropertiesMixin, {
    name_search: function (name, domain, operator, limit) {
        /* Custom code to override/extend core */
    },
});

return {
    DataSet: DataSet,
};

});

这篇关于如何在odoo中继承或覆盖js文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆