首页 > 解决方案 > 在 Odoo12 中从 Jquery 调用 python 函数?

问题描述

我创建了一个update在前端命名的按钮。

我需要在使用 jquery 单击按钮时运行我在 python 文件中编写的函数

xml

<t>
<button id="update_health_profile_front" 
        class="btn btn-primary" 
        type="button">Update
</button>
</t>

py


 @api.multi
    def update_health_profile(self):
        # partner = self.partner_id
        #some_method

js


$('#update_health_profile_front').click(function(event){
            var rpc = require('web.rpc');
            rpc.query({
            model: 'health.profile',
            method: 'update_health_profile',
        })
        .then(function(result){
            for (i= 0; i< result.length; i++){
                    console.log("result",result[i]);
             }

          },);

它不起作用,我认为这也不是正确的方法,有人可以分享一些知识吗?

标签: pythonjqueryodoo-12

解决方案


那么你可以试试这个,我认为它应该工作。

$('#update_health_profile_front').click(function(event){
            var rpc = require('web.rpc');
            rpc.query({
            model: 'this.name',
            method: 'update_health_profile'
        })
        .then(function(result){
            for (i= 0; i< result.length; i++){
                    console.log("result",result[i]);
             }

          },);


推荐阅读