【发布时间】:2016-02-15 13:56:13
【问题描述】:
jQuery 似乎在 react 组件中运行良好,但是,当我尝试在 react 组件中使用 jquery 应用样式时,它不起作用。在下面的代码中,每个循环中的console.log(eachVisitedTopic) 都按预期返回了正确的结果。
topicsVisited(arr){
$(function() {
$.each(arr, function(key, eachVisitedTopic) {
console.log(eachVisitedTopic);
$('.single-topic[data-topic-id="' + eachVisitedTopic + '"]').css({
'background-color': 'red'
});
});
});
};
标记
import {React, ReactDOM} from '../../../../build/react';
export default class SingleTopicBox extends React.Component {
render() {
return (
<div>
<div className="col-sm-2">
<div className="single-topic" data-topic-id={this.props.topicID} onClick={() => this.props.onClick(this.props.topicID)}>
{this.props.label}
{this.props.topicID}
</div>
</div>
</div>
);
}
};
【问题讨论】:
-
你能举一个你的反应标记的例子吗?
-
我认为您应该为此使用
style属性。这是处理样式状态的更强大的方法。 -
@FatihErikli 我已经添加了标记,您能否为我的案例展示一个示例。
标签: javascript jquery css reactjs