虽然我在 reactjs 组件(组件名称为 renderLocationLink)的渲染方法返回的 html 中包含了 Một 标签的 onclick 处理程序,但渲染正确地发生了 onclick 处理程序属性没有出现在网页上呈现的 html 中。我想要无法确定问题所在,这是代码
var feedApp = React.createClass({
getInitialState: function(){
return {
data : [
{display_name:"Rao",content:"this is Rao post",links:['link1','link2','link3']},
{display_name:"Sultan",content:"this is Sultans",links:['link4','link5','link6']},
{display_name:"John",content:"this is John post",links:['link7','link8','link9']}
]
}
},
fetchFeedsFromUrl: function(){
console.log('Onclick triggered');
},
render: function(){
return ()
}
})
var Feeds = React.createClass({
render: function(){
var onClickfunc = this.props.onClick;
var feeds = this.props.data.map(function(feed){
return (
)
});
return(
{feeds}
)
}
})
var oneFeed = React.createClass({
render: function() {
return (
{this.props.name}
{this.props.content}
)
}
});
var renderLocationLink = React.createClass({
render: function(){
var onClick = this.props.onClick;
var locationLinks = this.props.linkArray.map(function(link,index){
return ({link} )
})
return ( {locationLinks}
)
}
})
React.renderComponent(feedApp(null),document.body);
您不需要在 map 函数中引用“this”来访问局部变量。当您尝试访问 onClick 变量时删除“this”。
var renderLocationLink = React.createClass({
render: function(){
var onClick = this.props.onClick;
var locationLinks = this.props.linkArray.map(function(link,index){
return ({link} )
})
return ( {locationLinks}
)
}
})
Tôi là một lập trình viên xuất sắc, rất giỏi!