如何解决在 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]);
}
},);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。