zoukankan      html  css  js  c++  java
  • odoo14在列表视图里添加自定义按钮

    static/js/xxxx.js   这里定义按钮

    odoo.define('add.tree.view.buttons', function (require) { "use strict"; var core = require('web.core'); var ListController = require('web.ListController'); var ListView = require('web.ListView'); var viewRegistry = require('web.view_registry'); var qweb = core.qweb; var AddListViewController = ListController.extend({ buttons_template: 'AddsListView.buttons', /** * Extends the renderButtons function of ListView by adding an event listener * on the bill upload button. * * @override */ renderButtons: function () { this._super.apply(this, arguments); // Possibly sets this.$buttons if (this.$buttons) { var self = this; this.$buttons.on('click', '.o_button_add_tree_btn', function () { var actived_ids = []; var select_value = $('tbody .o_list_record_selector input'); var state = self.model.get(self.handle, {raw: true});
    //这里是获取列表中选中的record
    for (var i=0;i<select_value.length;i++){
    if (select_value[i].checked===true){

    actived_ids.push(state.res_ids[i]);

    }

    }
    self.do_action({ type: 'ir.actions.act_window', res_model: 'test.wizard',//向导模型 target: 'new', views: [[false, 'form']], context: {active_ids:actived_ids}, }); }); } } }); //注册你的插件 var AddsListView = ListView.extend({ config: _.extend({}, ListView.prototype.config, { Controller: AddListViewController, }), }); viewRegistry.add('add_buttons_tree', AddsListView); });

    这里添加按钮:static/xml/xxxx.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <templates>
        <t t-extend="ListView.buttons" t-name="AddsListView.buttons">
            <t t-jquery="button.o_button_import" t-operation="replace"></t><!--隐藏列表导入按钮-->
     <t t-jquery="button.o_list_button_add" t-operation="after"> <!--将新加按钮放置创建按钮后面--> <button type="button" class="btn btn-danger o_button_add_tree_btn" title="按钮1">按钮1</button> </t> </t> </templates>

    导入你的js

    <odoo>
        <data>
            <template id="assets_backend" name="add list buttons" inherit_id = "web.assets_backend">
                <xpath expr="." position="inside">
                    <script type="text/javascript" src="/mde_name/static/src/js/add_tree_view_button.js"></script>
                </xpath>
            </template>
        </data>
    </odoo>

    最后在列表视图中引用:js_class="AAAAAAAAA"

        <tree string="" js_class="add_buttons_tree" delete="0" >
    心有猛虎,细嗅蔷薇
  • 相关阅读:
    java实现验证码功能
    C# 自动注册OCX方法
    wamp出现You don’t have permission to access/on this server提示
    C# 图像旋转代码
    C# 实现图像快速 水平 垂直 翻转
    C#创建Graphics对象的方法
    winform控件大小改变是防止背景重绘导致的闪烁(转载)
    C#中DataTable中Rows.Add 和 ImportRow 对比
    MongoDb C# 驱动操作示例
    解决c#所有单线程单元(STA)线程都应使用泵式等待基元(如 CoWaitForMultipleHandles),并在运行时间很长的操作过程中定期发送消息。 转载
  • 原文地址:https://www.cnblogs.com/1314520xh/p/14533219.html
Copyright © 2011-2022 走看看