我正在使用Magento EE 2.1.1,並且我需要擴展位於lib/web/mage/collapsible.js
中的activate
方法功能。但我不能找到Magento的文檔和谷歌搜索的正確方法,所以這裏是我的嘗試,什麼是對每個問題:無法覆蓋magento 2中的collapsible.js
嘗試1:
- 創建以下文件:
namespace_module_dir /視圖/前端/網絡/ JS /可摺疊mixin.js
define([
'jquery'
], function ($) {
'use strict';
var mixin = {
activate: function() {
if (!this.options.disabled) {
if (this.options.animate) {
this._animate(showProps);
} else {
// my custom code goes here ...
this.content.show();
}
this._open();
}
}
};
return function (target) {
return target.extend(mixin);
};
});
- 創建requirejs-config文件
namespace_module_dir /視圖/前端/ requirejs-config.js
var config = {
config: {
mixins: {
'mage/collapsible': {
'<namespace_module>/js/collapsible-mixin': true
}
}
}
};
的問題是:
- 嘗試2:
- 創建requirejs-config文件
- 嘗試3:
- 創建以下文件:
- 創建requirejs-config文件
namespace_module_dir /視圖/frontend/requirejs-config.js
var config = {
map: {
'*': {
collapsible: '<namespace_module>/js/collapsible-map'
}
}
};
問題是: 不管是什麼collapsible-map.js
的內容,它沒有得到加載(創建可摺疊map.js文件),甚至以爲我可以看到我在自動requirejs-config.js
內容生成requirejs-config.js
文件由magento和defalut magento collapsible.js文件加載。
namespace_module_dir /視圖/前端/網絡/ JS /可摺疊地圖。JS
define([
'jquery',
'jquery/ui',
'mage/collapsible'
], function ($) {
"use strict";
$.widget('<namespace_module>.collapsible', $.mage.collapsible, {
activate: function() {
if (!this.options.disabled) {
if (this.options.animate) {
this._animate(showProps);
} else {
// custome code goes here ...
this.content.show();
}
this._open();
}
}
});
return $.ctv.collapsible;
});
namespace_module_dir /視圖/前端/ requirejs-config.js
var config = {
map: {
'*': {
'mage/collapsible': '<namespace_module>/js/collapsible-mixin'
}
}
};
問題是:
在那裏進行調試發現typeof $.mage.collapsible = undefined
所以請告訴我,我錯過了什麼,什麼是遵循的最佳途徑? :(
感謝inadvance ...