Javascript onClick事件未触发reactjs
Javascript onClick事件未触发reactjs,javascript,reactjs,Javascript,Reactjs,保险商实验室{ 列表样式类型:无; 保证金:0; 填充:0; } 李{ 显示:内联; } #外{ 左缘:20%; } #图标{ 显示:内联; } 反应图像滑块 var Slider=React.createClass({changeImage:function(e){console.log(“我在这里”);},render:function(){var lib=this.props.imageData;返回 {lib.map(函数(l){return {l.name} }) } ; }
保险商实验室{
列表样式类型:无;
保证金:0;
填充:0;
}
李{
显示:内联;
}
#外{
左缘:20%;
}
#图标{
显示:内联;
}
反应图像滑块
var Slider=React.createClass({changeImage:function(e){console.log(“我在这里”);},render:function(){var lib=this.props.imageData;返回
{lib.map(函数(l){return
-
{l.name}
}) }
; } } );
var arr_img=[{name:'Image1',url:'http://placehold.it/940x528,图标:'http://placehold.it/100x100'},{name:'Image2',url:'http://placehold.it/940x528,图标:'http://placehold.it/100x100'},{name:'Image3',url:'http://placehold.it/940x528',
图标:'http://placehold.it/100x100'},{name:'Image4',url:'http://placehold.it/940x528,图标:'http://placehold.it/100x100'},{name:'Image5',url:'http://placehold.it/940x528,图标:'http://placehold.it/100x100'},{name:'Image6',url:'http://placehold.it/940x528',
图标:'http://placehold.it/100x100'},{name:'Image7',url:'http://placehold.it/940x528,图标:'http://placehold.it/100x100'},{name:'Image8',url:'http://placehold.it/940x528,图标:'http://placehold.it/100x100'} ];
反应(
,document.body);
问题在于,this.changeImage
在传入时将未定义,因为您需要设置要传递给map的函数的范围:
// Add `this` as a second parameter
lib.map(function(l){ }, this);
我应该说,这与React无关,而与简单的JavaScript有关。问题是,
this.changeImage
在传入时将是未定义的,因为您需要设置要传递给map的函数的范围:
// Add `this` as a second parameter
lib.map(function(l){ }, this);
我应该说,这与React无关,而与简单的JavaScript有关。问题是,
this.changeImage
在传入时将是未定义的,因为您需要设置要传递给map的函数的范围:
// Add `this` as a second parameter
lib.map(function(l){ }, this);
我应该说,这与React无关,而与简单的JavaScript有关。问题是,
this.changeImage
在传入时将是未定义的,因为您需要设置要传递给map的函数的范围:
// Add `this` as a second parameter
lib.map(function(l){ }, this);
我应该说,这与React无关,一切都与简单的JavaScript有关