Odoo10 - How to do javascript

前端 未结 1 1041
孤城傲影
孤城傲影 2021-01-28 19:31

I must be doing something completely wrong:

odoo.define(\'my_module.popups\', function (require) {
    \'use strict\';
    var ajax = require(\'web.ajax\');
             


        
相关标签:
1条回答
  • 2021-01-28 19:32

    I hear you, I think the secrets of Odoo's js framework are the secret weapon a lot of people like to keep to themselves. I am sure it is all completely obvious if you spent the last 4 years working with backbone, requirejs and underscore. Sadly thats not me.

    If you take a look at the notification module in /addons/web/static/src/js/widgets/notification.js you should be able to see what they are doing. Some things that might help you are put some logging in to see if your scripts are being loaded and when. For what you are trying to do you will need to provide some events mapping. There is an example in the file I mentioned. In your jsmodule you will create an object which has an events attribute looking something like this.

    events: {
        'click .o_close': function(e) {
            e.preventDefault();
            this.destroy(true);
        },
        'hover .my_widget_class': function(e){
            // your code here
        },
    },
    

    Do not take the above code literally. You need an event that triggers you widget to be appended to dom at some point.

    0 讨论(0)
提交回复
热议问题