【问题标题】:Javascript identifier for widget in OdooOdoo 中小部件的 Javascript 标识符
【发布时间】:2017-10-04 05:59:12
【问题描述】:

如果视图中有两个widget。你对第一个小部件做了一些事情,并且你想更新(调用display_field)第二个小部件。如何为第二个小部件设置identifier

例如在 widget 的扩展定义中:

local.FieldNewWidget = instance.web.form.AbstractField.extend({
    init: function(parent, options) {
    },
    events: {
        'click .oe_new_input_button': 'open_new_specific_form',
    },
    start: function() {
    },
    display_field: function() {
    },
    render_value: function() {
    },
    open_new_specific_form: function(event) {
        var self = this;

        var new_action = {
            type: 'ir.actions.act_window',
            name: $(event.target).data('name'),
            res_model: $(event.target).data('data-model'),
            res_id: $(event.target).data('res-id'),
            view_mode: 'form',
            view_type: 'form',
            views: [[false, 'form']],
            target: 'new',
            context: {
            },
            flags: {'form': {'action_buttons': true}},
        }

        self.do_action(new_action, {
            on_close: function() {
                // I want to refresh (call display_field) the second widget here.
                // What is the identifier for the second widget?
            },
        });
    },
});

【问题讨论】:

    标签: javascript python openerp odoo-8


    【解决方案1】:

    我认为这会起作用,但我不知道这是否是最佳解决方案。我认为每个小部件都通过使用 (this.view) 知道它的女巫视图。为什么不使用特殊事件从一个小部件触发它并在另一个小部件中监听它。

    例如在小部件上注册一个事件监听器来监听视图上的属性变化:

             //in first widget register the event listener:
             this.view.on('property_name', this, this.your_method);
    
    
    
            // in second widget trigger the event by setting the value
            this.view.set('property_name', a_value);
    

    我是 odoo javascript 的新手,如果这对你有用,请告诉我,我认为通过使用事件触发而不改变属性有更好的解决方案。

    【讨论】:

    • 如果您举例说明如何在视图中触发事件会很棒
    • 只需在每个小部件的 init 或 start 函数中添加这一行
    • 我明白了,所以以编程方式设置视图属性。对不起,我之前没有注意到它
    • 有一件事不要忘记调用widget 的super in init 函数,因为您将中断由odoo 管理的关系paretn child。 _super.apply(this, arguments)
    • 是的,我调用了父构造函数和方法。我从示例代码中省略了那几行,因为我想有更短的帖子并专注于我遇到问题的部分。感谢谢里夫的关心
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-24
    • 1970-01-01
    • 2019-12-06
    • 2020-04-13
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    相关资源
    最近更新 更多