簡體   English   中英

如何在 Odoo 8 中調用自定義 JS 文件?

[英]How to call a custom JS file in Odoo 8?

我有一個名為student的模型。 我也有學生模型的表單視圖樹視圖 我想要做的是僅在加載學生模型的表單視圖時調用我的自定義 javascript 文件。 是否可以? 如何實現這一目標? 謝謝。

我試過的是......

openerp.student= function (instance) {

instance.web.FormView.include({

    load_form: function(data) {
        var self = this;
        if (data.model === "student") {
            altert('HELLO');
            console.log('BLAH BLAH');
        }
        return this._super(data);
    },

});
};

您可以覆蓋FormViewload_form方法。

openerp.module_name= function (instance) {

    instance.web.FormView.include({

        load_form: function(data) {
            var self = this;
            if (data.model === "student") {
                // Your custom code
            }
            return this._super(data);
        },

    });
};

要添加上面的代碼,請檢查此鏈接繼承或覆蓋-js

可以通過像 Odoo 使用account_move_line_quickadd那樣擴展FormFiew來添加新的視圖模式。

openerp.your_module_name = function (instance) {
    var _t = instance.web._t,
    _lt = instance.web._lt;
    var QWeb = instance.web.qweb;

    instance.web.your_module_name = instance.web.your_module_name || {};

    instance.web.views.add('student_form', 'instance.web.StudentFormView');

    instance.web.StudentFormView = instance.web.FormView.extend({

        load_form: function(data) {
            var self = this;
            // Add your custom code here
            return this._super(data);
        },
    });
};

您只需要將新模式添加到窗口操作中即可。

<record id="student_action" model="ir.actions.act_window">
        <field name="name">student.action</field>
        <field name="res_model">student</field>
        <field name="view_mode">student_form,tree</field>
        ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM