簡體   English   中英

如何在 magento 2 的自定義模塊中覆蓋第三方模塊 Js 小部件

[英]How to override third party module Js widget in custom module in magento 2

在這里,我正在嘗試使用 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 並清除緩存然后我收到“Uncaught TypeError: base is not a constructor”錯誤

認為您應該將custom.amShopbyAjax更改為mage.amShopbyAjax

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

小部件別名應該類似於目標小部件,並且應該返回父別名的小部件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM