openerp Web 客户端 6.1:如何覆盖基本 javascript 函数

发布于 2024-12-26 18:00:34 字数 1251 浏览 2 评论 0原文

我正在寻找一种方法来覆盖一些 openerp web js 核心功能,例如“on_logout”。

该文档缺乏说明(如您在 我的帖子) 和 helloworld module 告诉您可以像

openerp.web_hello = function(openerp) {

openerp.web.SearchView = openerp.web.SearchView.extend({
    init:function() {
        this._super.apply(this,arguments);
        this.on_search.add(function(){console.log('hello');});
    }
});

// here you may tweak globals object, if any, and play with on_* or do_* callbacks on them

openerp.web.Login = openerp.web.Login.extend({
    start: function() {
        console.log('Hello there');
        this._super.apply(this,arguments);
    }
});

};

在我的模块中一样执行此操作:

openerp.mytest = function(openerp){

    openerp.web.WebClient = openerp.web.WebClient.extend({
        on_logout: function() {
            alert('mine');
            [...]
        },
    });
}

我知道 js 已加载,因为在此定义之外放置警报是有效的。

这是怎么回事?

I'm looking for a way to override some openerp web js core functions such as "on_logout".

The docs lack of instructions (as you can see in my post) and the helloworld module tells you that you can do it like

openerp.web_hello = function(openerp) {

openerp.web.SearchView = openerp.web.SearchView.extend({
    init:function() {
        this._super.apply(this,arguments);
        this.on_search.add(function(){console.log('hello');});
    }
});

// here you may tweak globals object, if any, and play with on_* or do_* callbacks on them

openerp.web.Login = openerp.web.Login.extend({
    start: function() {
        console.log('Hello there');
        this._super.apply(this,arguments);
    }
});

};

In my module I'm doing this:

openerp.mytest = function(openerp){

    openerp.web.WebClient = openerp.web.WebClient.extend({
        on_logout: function() {
            alert('mine');
            [...]
        },
    });
}

I know js is loaded since putting an alert outside this definition works.

What's wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欢烬 2025-01-02 18:00:34

这是一个有点特殊的问题,因为您想要更改已经实例化的对象的原型(类,如果您愿意的话)(WebClient 实例是系统的根,因此在您的代码编写时它可能已经存在)已加载,因此创建新的 WebClient“类”不会改变现有实例)。

在这种情况下,你不能用子类替换该类,你必须重新打开该类(以类似于 Ruby 的方式),因为类对象上有一个 include 方法,哪个应该工作:(

openerp.mytest = function(openerp) {
    openerp.web.WebClient.include({
        on_logout: function() {
            alert('mine');
            this._super.apply(this, arguments);
        }
    });
}

就像在Ruby中一样,this._super绑定到您要替换的方法(如果有的话)以进行就地类更改)

如果您检查view_list_editable.js 实现文件,它提供了示例因为它需要重新打开并更改列表视图的代码以添加可编辑性。

That's a bit of a special issue since you want to alter the prototype (the class, if you will) of an object which is already instantiated (a WebClient instance is the root of the system, so it's probably already there by the time your code is loaded, therefore creating a new WebClient "class" won't alter the existing instance).

In that case, you can't replace the class with a subclass, you have to re-open the class (in a manner similar to Ruby), for that there is an include method on class objects, which should work:

openerp.mytest = function(openerp) {
    openerp.web.WebClient.include({
        on_logout: function() {
            alert('mine');
            this._super.apply(this, arguments);
        }
    });
}

(as in Ruby, this._super is bound to the method you're replacing, if any, for in-place class alterations)

If you check the view_list_editable.js implementation file, it provides examples of that since it needs to reopen and alter the listview's code in order to add editability.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文