openerp web client 6.1:如何覆盖基本的javascript函数

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

文档缺乏说明(如您在my post中所见),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已加载,因为在此定义之外放置警报有效.

这有什么不对?

解决方法

这是一个特殊的问题,因为您想要更改已经实例化的对象的原型(类,如果您愿意)(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实现文件,它会提供示例,因为它需要重新打开并更改listview的代码才能添加可编辑性.

相关文章

vue阻止冒泡事件 阻止点击事件的执行 <div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些