0
我无法将我的道具传递给子组件,因此无法使用React。我已阅读文档,但我仍然对需要采取哪些步骤感到困惑。这是通过使用Ruby on Rails与react_on_rails gem完成的。在这一点上,Redux没有被使用,我仍然在与React学习。将道具传递给子组件
我一个变量从轨使用react_component具有以下发送:
index.html.erb
<%= react_component('Lifts', props: @lifts, prerender: true) %>
试图把它捡起来的反应。数据显示在Chrome开发工具的元素部分下。但是,我假设也许我没有正确地绑定数据。似乎没有出现在LiftsList.jsx中。也许解决办法很明显,但现在它真的逃脱了我。
Lifts.jsx
import React, { PropTypes } from 'react';
import LiftsList from './LiftsList';
import Lift from './Lift';
export default class Lifts extends React.Component {
constructor(props, _railsContext) {
super(props);
this.state = {
id: props.id,
date: props.date,
liftname: props.liftname,
weightlifted: props.weightlifted,
repsformed: props.repsformed,
}
}
render() {
return (
<div className="container" style={{display : 'inline-block'}}>
<ul>
<LiftsList lifts = {this.state.lifts} />
</ul>
</div>
);
}
}
LiftsList.jsx
import React, {PropTypes} from 'react';
import Lift from './Lift';
export default class LiftsList extends React.Component {
render() {
let lifts = this.state.lifts.map(lift =>
<Lift key={prop.id} {...lift} />);
return (
<div>
<div>???</div>
</div>
);
}
}
Lift.jsx
import React, {PropTypes} from 'react';
export default class Lift extends React.Component {
render() {
return (
<ul>
<li>{this.props.id}</li>
<li>{this.props.date}</li>
<li>{this.props.liftname}</li>
<li>{this.props.ismetric}</li>
<li>{this.props.weightlifted}</li>
<li>{this.props.repsformed}</li>
</ul>
);
}
}
'您尚未在状态中定义提升。 –