Javascript Odoo:Odoo树状视图标题中的自定义按钮不会触发python函数

Javascript Odoo:Odoo树状视图标题中的自定义按钮不会触发python函数,javascript,python,xml,treeview,odoo,Javascript,Python,Xml,Treeview,Odoo,基本信息: 奥多版本:10.0 模块名称:simcard 型号名称:simcard.simcard 目标:在树状视图的标题中添加一个同步按钮,并将其链接到python函数 我的模板文件(template.xml): My python文件函数(models.py): 我的视图文件(view.xml): “同步”按钮出现在树视图标题中,但单击该按钮时,我无法调用我的函数。有什么我遗漏的吗???你的js代码中有一些错误,下面的代码应该可以正常工作 odoo.define('simcard_piavi

基本信息

奥多版本:10.0

模块名称:simcard

型号名称:simcard.simcard

目标:在树状视图的标题中添加一个同步按钮,并将其链接到python函数

我的模板文件(template.xml):

My python文件函数(models.py):

我的视图文件(view.xml):


“同步”按钮出现在树视图标题中,但单击该按钮时,我无法调用我的函数。有什么我遗漏的吗???

你的js代码中有一些错误,下面的代码应该可以正常工作

odoo.define('simcard_piavita.tree_view_button', function (require){
"use strict";
    var ListView = require('web.ListView');
    var Model = require('web.DataModel');
    ListView.include({
        render_buttons: function() {
            this._super.apply(this, arguments)
            if (this.$buttons) {
                var btn = this.$buttons.find('.sync_button')
                btn.on('click', this.proxy('do_sync'))
            }
       },
        do_sync: function() {
            new Model('simcard_piavita.simcard_piavita')
                .call('my_function', [[]])
                .done(function(result) {
                    alert('done')
                })
        }
    });
});

一个问题:这个javascript文档在哪里?我想了解javascript代码中发生了什么,以便创建更复杂的代码。还有一个问题:如何将变量从javascript传递到python函数?谢谢。函数调用的参数必须在线。call('my_function',[[]])我尝试调用('my_function',[[my_argument]]),但不起作用
odoo.define('simcard.tree_view_button', function (require){"use strict";
    var ListView = instance.web.ListView;
    ListView.include({
    render_buttons: function() {

   // GET BUTTON REFERENCE
    this._super.apply(this, arguments)
    if (this.$buttons) {
    var btn = this.$buttons.find('.sync_button')
    }

   // PERFORM THE ACTION
    btn.on('click', this.proxy('do_sync'))

   },
    do_sync: function() {
    new instance.web.Model('simcard.simcard')
    .call('my_function', [[]])
    .done(function(result) {
    alert('done')
    })
    }
    });
   }
  def my_function(self): 
    print 'fooooooooooooooo' 
   <?xml version="1.0" encoding="utf-8"?>
   <odoo>
    <data>
     <template id="assets_backend" name="tree view menu" 
      inherit_id="web.assets_backend">               
        <xpath expr="." position="inside">                   
           <script type="text/javascript" 
               src="simcard/static/js/tree_view_button.js"> 
           </script>               
        </xpath>           
    </template> 
  </data>
 </odoo>
  # -*- coding: utf-8 -*-
 {
'name': "simcard",

'summary': """
    Store them""",

'description': """
    Store them""",


# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/odoo/addons/base/module/module_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.1',

# any module necessary for this one to work correctly
'depends': ['base'],

# always loaded
'data': [
    # 'security/ir.model.access.csv',
    'views/views.xml',
    'views/templates.xml',
],

'qweb': ['static/xml/tree_view_button.xml'],

# only loaded in demonstration mode
'demo': [
    'demo/demo.xml',
],
'installable': True,
'auto_install': False,
'application': True,
}
odoo.define('simcard_piavita.tree_view_button', function (require){
"use strict";
    var ListView = require('web.ListView');
    var Model = require('web.DataModel');
    ListView.include({
        render_buttons: function() {
            this._super.apply(this, arguments)
            if (this.$buttons) {
                var btn = this.$buttons.find('.sync_button')
                btn.on('click', this.proxy('do_sync'))
            }
       },
        do_sync: function() {
            new Model('simcard_piavita.simcard_piavita')
                .call('my_function', [[]])
                .done(function(result) {
                    alert('done')
                })
        }
    });
});