【问题标题】:How to override third party module Js widget in custom module in magento 2如何在magento 2的自定义模块中覆盖第三方模块Js小部件
【发布时间】:2020-05-22 11:34:36
【问题描述】:

在这里,我正在尝试使用 mixin 在我的模块中扩展 Amasty js 小部件。 我创建了如下所示的 requirejs-config.js 文件

var config = {
    config: {
        mixins: {
            'amShopbyAjax': {
                'vendor_CustomCatalog/js/amasty/amShopbyAjax-override': true
            }
        }
    }
};

我已经创建了如下的js文件

define([
    "jquery",
    "jquery-ui-modules/widget"
], function ($) {
    'use strict';
    var amShopbyWidgetMixin = {
        selectors: {
            category_products_wrapper: '#amasty-shopby-category-product-list',
        },

        reloadHtml: function (data) {
            console.log("Sdfsdfsdf");
            return this._super();
        },
        callAjax: function (clearUrl, data, pushState, cacheKey, isSorting) {
            console.log("sdnjkasndnsadj");
            return this._super();
        }
    };
    return function (targetWidget) {
        $.widget('custom.amShopbyAjax', targetWidget, amShopbyWidgetMixin);
        return $.custom.amShopbyAjax;
    };
});

之后我运行 sudo bin/magento setup:static-content:deploy -f 并清除缓存,然后我收到“未捕获的 TypeError: base is not a constructor”错误

【问题讨论】:

    标签: javascript jquery magento2


    【解决方案1】:

    认为您应该将custom.amShopbyAjax 更改为mage.amShopbyAjax

    return function (targetWidget) {
        $.widget('mage.amShopbyAjax', targetWidget, amShopbyWidgetMixin);
        return $.mage.amShopbyAjax;
    };
    

    小部件别名应与目标小部件相同,并应返回父别名的小部件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 2016-05-18
      • 2016-12-06
      • 1970-01-01
      相关资源
      最近更新 更多