我正在使用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 ...