客户端 Web - 如何随时获取当前记录 ID [英] client web - how to get current record id at any time

查看:28
本文介绍了客户端 Web - 如何随时获取当前记录 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试处理基于工作流状态的不同权限" 问题,但我正在努力解决这样一个事实,即似乎不可能随时"获取当前对象的 id,这是获得该对象许可所必需的.我的意思是我设法从客户端状态获取它 遵循 jquery bbq 文档 喜欢:

I'm trying to work on the "different permissions based on workflow state" issue but I'm struggling with the fact that it seems impossible to get the id of the current object 'at any time' that is necessary in order to get the permission of that object. What I mean is that I manage to get it from the client state following jquery bbq docs like:

$.bbq.getState().id

但看起来这只有在完整的页面加载后才可行.我通过在主视图事件中放置一些警报来对此进行调查,例如:

BUT it looks like this is doable only AFTER a complete page load. I investigated this by placing some alert in the main view events, like:

openerp.web.PageView = openerp.web.PageView.extend({
    on_loaded: function(data) {
        this._super(data);
        alert('page load ' + $.bbq.getState().id);
    },
    do_show: function() {
        this._super();
        alert('page show ' + $.bbq.getState().id);
    },
    reload: function() {
        this._super();
        alert('page reload ' + $.bbq.getState().id);
    },
    on_record_loaded: function(record) {
        this._super(record);
        alert('record loaded ' + $.bbq.getState().id);
    }
});

并且我发现当您打开页面视图(例如,通过单击搜索视图中的项目)时,您总是未定义".

and I found that when you open the page view (by clicking on an item in a search view, for instance) you get always "undefined".

然后,当使用分页导航从一个对象传递到另一个对象时,您将其设置为重新加载"和on_record_loaded".然后,当您点击编辑"按钮时,您又会错过它.

Then, you get it into "reload" and "on_record_loaded" when passing from an object to another using paged navigation. And then, you miss it again when you click on the "edit" button.

在表单视图中,我仅在第一次加载时成功获得了它,因为似乎有一些缓存就位.因此,如果我将 pdb 放入 Web 客户端的 fields_view_get 并将其放入表单init_view"中:

In the form view I successfully got it only on the 1st load because it seems that some caching is in-place. So that, if I place a pdb into web client's fields_view_get and I do this into the form "init_view":

var ids = [];
if ($.bbq.getState().id){
    ids = [parseInt($.bbq.getState().id)];
}
console.log(ids);
return this.rpc("/web/view/load", {
    "model": this.model,
    "view_id": this.view_id,
    "view_type": "form",
    toolbar: this.options.sidebar,
    context: context,
    ids: ids,
    }, this.on_loaded);

我只在第一次加载页面时得到它.如果我从

I get it only the 1st time that the page gets loaded. The same happen if I take ids from

this.dataset.ids

我查看了核心 Web 模块的任何地方,但找不到合适的 API 并且看起来很奇怪(尤其是在数据集上)我们没有获取/处理当前记录的正确方法/s.甚至上下文和会话也没有任何相关信息.

I looked anywhere at the core web module and I can't find a proper API for this and it looks weird (above all on dataset) that we don't have a proper way for getting/working on the current record/s. Even the context and the session do not have any information about that.

可能我应该在第一次加载时将其存储到视图本身中...

Probably I should store this into the view itself on 1st load...

提前感谢您的指点.

推荐答案

尝试:

this.view.datarecord.id

this.view.datarecord.id

表单视图中的OpenERP 7:使用谷歌浏览器调试

OpenERP 7 in form view: debugged using google chrome

这篇关于客户端 Web - 如何随时获取当前记录 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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