1.odoo中消息机制有几种,比如
(1).用于前端的消息机制core.bus.trigger/core.bus.on
(2).用于前后端消息通信的longpolling消息机制
2.前端消息通信的使用之前文章已经记录过,说一下前后端消息机制longpolling的使用
(1).前端部分:
this.call('bus_service', 'addChannel', 'menu_badge');
this.call('bus_service', 'onNotification', self, this._onNotification);
第一步:添加你要发送消息的频道,此处为"menu_badge"
第二步:监听后端的消息
_onNotification是处理接收到的消息的函数,bus_service是bus模块中全局注册的,可以直接使用,无需引入文件
(2).后端部分:
self.env['bus.bus'].sendone('menu_badge', {
menu_id: count
})
"menu_badge"为频道号, 第二个参数是你要发送的消息内容