python - 在 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]);
}
},);
它不起作用,我认为这也不是正确的方法,有人可以分享一些知识吗?
解决方案
那么你可以试试这个,我认为它应该工作。
$('#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]);
}
},);
推荐阅读
- hyperledger-fabric - 在 v2.1 Hyperledger Fabric 网络中升级链码失败
- javascript - 如何使用 reactjs 的 package.json 脚本使文件可运行?
- azure-functions - ILogger 的所有条目都到哪里去了?
- python - Python:无法从更高的目录导入类
- aws-lambda - 如何将所需的输入从应用程序传递到 Amazon Lex Bot?
- php - 如何让 Laravel 读取现有的列?
- node.js - 节点访问权限 | 动态网址授权
- ruby-on-rails - 尝试访问我在 docker 内的应用程序时出现阻止主机错误
- node.js - 团队中的自适应卡不起作用 - REST API
- android - Android Emulator 向 Azure Api 发送本地请求导致 400 错误