比方说,你要在产品的编辑页面从js/mage/adminhtml/product.js
覆盖function loadImage
。
创建自定义JS: js/myfolder/myproduct.js
:
Product.Gallery.addMethods({
loadImage : function(file) {
alert('hi there');
var image = this.getImageByFile(file);
this.getFileElement(file, 'cell-image img').src = image.url;
this.getFileElement(file, 'cell-image img').show();
this.getFileElement(file, 'cell-image .place-holder').hide();
}
});
参考:http://prototypejs.org/learn/class-inheritance.html
然后在你的布局文件添加自定义的JS:
<adminhtml_catalog_product_edit>
<reference name="head">
<action method="addJs"><script>myfolder/myproduct.js</script></action>
</reference>
</adminhtml_catalog_product_edit>
使用这种方法,function loadImage
会只有包含您的js/myfolder/myproduct.js
才会被覆盖。
PS: 确保js/myfolder/myproduct.js
是js/mage/adminhtml/product.js
后包括(尽管它就是这样的,因为默认情况下js/mage/adminhtml/product.js
中包括<default>
标签)
嗨ivantedja谢谢您的回答。我做了根据你的指令和它的工作为上述功能,但当我尝试重写一些其他功能,如 updateImages:function(file){} 它显示我this.getFileElement(文件,“单元格标签输入”)是undefined.in上面的代码我添加了两个额外的字段与名称链接和target_window和这个代码工作在核心文件,但不是在我的自定义JS? –
嗨,我只通过重命名完成并将js文件直接包含在我的phtml中,比如 它的工作原理。 –
你在哪个页面重写它?和哪个功能? updateImage或updateImages? – ivantedja