javascript - 修改开始: function of var EditMenuDialog in Odoo

标签 javascript odoo-10 odoo-website

我需要修改 odoo website.contentMenu.js 文件的 EditMenuDialog var 的启动函数中的值。修改需要在我的自定义模块js文件中完成。

https://github.com/odoo/odoo/blob/10.0/addons/website/static/src/js/website.contentMenu.js#L210

此处 maxLevels 的值为 2:

start: function () {
    var r = this._super.apply(this, arguments);
    this.$('.oe_menu_editor').nestedSortable({
        listType: 'ul',
        handle: 'div',
        items: 'li',
        maxLevels: 2,
        toleranceElement: '> div',
        forcePlaceholderSize: true,
        opacity: 0.6,
        placeholder: 'oe_menu_placeholder',
        tolerance: 'pointer',
        attribute: 'data-menu-id',
        expression: '()(.+)', // nestedSortable takes the second match of an expression (*sigh*)
    });
    return r;
},

对于我的模块,我需要将 maxLevels 更改为 3。我尝试重写自定义文件中的变量,但它不起作用。我怎样才能做到这一点?

最佳答案

我找到了在自定义模块中继承和修改odoo js函数的解决方案。代码如下:

odoo.define('your_module_name.js_name', function (require) {
'use strict';

// assign the variable EditMenuDialog of website module's contentModule
// js in a variable
var EditMenuDialog = require('website.contentMenu').EditMenuDialog;

// for modifying use the .include function
EditMenuDialog.include({
    start: function () {
        this.$('.oe_menu_editor').nestedSortable({
            listType: 'ul',
            handle: 'div',
            items: 'li',
            maxLevels: 3, // changed maxLevels from 2 to 3
            toleranceElement: '> div',
            forcePlaceholderSize: true,
            opacity: 0.6,
            placeholder: 'oe_menu_placeholder',
            tolerance: 'pointer',
            attribute: 'data-menu-id',
            expression: '()(.+)'
        });
    }
});
});

关于javascript - 修改开始: function of var EditMenuDialog in Odoo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44869400/

相关文章:

javascript - jQuery 使用 CSS 动画在点击时切换不透明度

Javascript获取框架的全部内容

javascript - Angular : $scope is not reading values from HTML

css - 为什么我的 pdf 报告在 Odoo 中没有很好地采用 CSS 样式?

javascript - 按钮单击背景图像更大的动画并加载新页面

javascript - 如何以编程方式更改 amStockChart 的缩放级别?

openerp - 将变量传递到模板中

odoo-9 - 从不同模型odoo 9获取数据

Odoo 10.0 更改 POS Logo

python - 通过 bool 复选标记激活表单中的字段 - Odoo v8