【发布时间】:2017-01-12 15:02:54
【问题描述】:
我正在实现一个引导屏幕,用户在该屏幕中选择 3 个以上的项目,并且在用户单击它后,一个紫色的叠加层会保留下来。
这是我的代码:
var RepeatModule = React.createClass({
getInitialState: function() {
return { items: this.props.items || [] }
},
componentWillMount: function() {
console.log("componentWillMount()")
this.setState({ items : data })
console.log(data,"data is here");
},
handleClick: function (e, item) {
this.setState({active: true});
},
render: function() {
var listItems = this.state.items.map(function(item) {
return (
<ListItem item={item}/>
);
});
return (
<div className="flex-container">
{listItems}
</div>
);
}
});
/* make the items stateless */
var ListItem = function(props) {
var backgroundImage = {
backgroundImage: 'url(' + props.item.pictureURL + ')'
};
return (
<div className="block-grid-item">
<a className="display-block card text-gray-darker">
<div onClick={handleClick} style={backgroundImage} className="card-img-wrap m-xs-0 placeholder placeholder-landscape">
</div>
<div className="card-meta">
<div className="vesta-hp-gifts-card-title text-gray-darker">{props.item.storeName}</div>
</div>
</a>
</div>
);
}
我尝试在我的 handleClick 函数中保持活动状态时遇到问题。
这是我的悬停 CSS 效果
.card-img-wrap::after
{
background-color: #000;
bottom: 0px;
content: "";
left: 0px;
opacity: 0;
position: absolute;
right: 0px;
top: 0px;
}
.card-img-wrap:hover::after
{
background-color: #000;
bottom: 0px;
content: "";
left: 0px;
opacity: 0;
position: absolute;
right: 0px;
top: 0px;
opacity: 0.6;
background-color: #5450DC;
}
为什么这不起作用?如何做到这一点?
【问题讨论】:
-
您没有将
handleClick传递给ListItem。即使那样,您也没有跟踪活动项目。 -
@xiaofan2406 如何将handleClick 传递给ListItem?
标签: javascript html css reactjs