Javascript ES6重写父方法
我目前正在定制react nuka旋转木马。我想覆盖carousel.js中的getDecoratorStyles方法。该类如下所示:Javascript ES6重写父方法,javascript,reactjs,ecmascript-6,Javascript,Reactjs,Ecmascript 6,我目前正在定制react nuka旋转木马。我想覆盖carousel.js中的getDecoratorStyles方法。该类如下所示: const Carousel = React.createClass({ ... render() { ... return ( <div style={assign(self.getDecoratorStyles(Decorator.position), Deco
const Carousel = React.createClass({
...
render() {
...
return (
<div
style={assign(self.getDecoratorStyles(Decorator.position), Decorator.style || {})}
className={'slider-decorator-' + index}
key={index}>
<Decorator.component
...
getDecoratorStyles(position) {
switch (position) {
case 'TopLeft': {
return {
position: 'absolute',
top: 0,
left: 0
}
...
const Carousel=React.createClass({
...
render(){
...
返回(
我想问题在于传递给carousel props的decorators
变量可能会覆盖getdecoratorstyle
方法中的样式。
传递给Carousel
类中道具的装饰器映射到render
方法中的元素。
请特别注意将样式指定给元素的行:
style={assign(self.getDecoratorStyles(Decorator.position), Decorator.style || {})}
结果是,如果相关的decorator包含它自己的样式,那么由getdecoratorstyle
方法生成的样式可以被覆盖。它应该可以工作。请确保您正在处理您实际需要的类的实例。此外,如果您使用的是transpiler,请确保它们完全支持您需要的样式,尽管我可能需要预期覆盖已在列表中…它不起作用:(我们使用webpack和babel,但我在配置这些东西和其他东西方面做得不好。您要传递给MXCarousel的道具的装饰器变量是什么?我有上一个和下一个按钮的装饰器,类似于默认的装饰器。这些装饰器是用于位置中心右和中心左?如果这不能解决问题,请检查您的装饰师
,并将其附加到答案中
style={assign(self.getDecoratorStyles(Decorator.position), Decorator.style || {})}