Odoo中小部件的Javascript标识符

时间:2017-10-04 05:59:12

标签: javascript python openerp odoo-8

如果视图中有两个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?
            },
        });
    },
});

1 个答案:

答案 0 :(得分: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的新手让我知道如果这适合你,我认为有一个更好的解决方案,通过使用事件触发而不改变属性。