私はコンポーネントから私のprops.commandをレンダリング問題を抱えているではありません何とかここに発生しますエラーはここに私のthis.props.commands.mapが機能
import { getCommand } from '../../actions/commandActions';
import { connect } from 'react-redux';
class Command extends React.Component {
constructor(props) {
super(props);
this.state = {
commands: []
};
}
componentWillMount(){
this.props.getCommand();
this.setState({commands: this.props.commands});
}
render(){
console.log('command props.commands: ', this.props.commands);
return (
<table className="table table-bordered table-responsive">
<thead>
<tr>
<th>Name</th>
<th>Command</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{
this.props.commands.map(function(commands) {
return
<tr>
<td>{commands.name}</td>
<td>{commands.command}</td>
<td>{commands._id}</td>
</tr>
})
}
</tbody>
</table>
);
}
}
Command.propTypes = {
getCommand: React.PropTypes.func.isRequired,
errors: React.PropTypes.object.isRequired
}
function mapStateToProps(state) {
return{
commands: state.commandReducer.commands,
errors: state.commandReducer.errors
}
}
export default connect(mapStateToProps, { getCommand })(Command);
あるthis.propsのはconsole.logです.commands:
command props.commands: Array[1]
0: Object_id: "5892c3d4d3128f231ab032bb"
command: "env $(cat .env) DEBUG=ow* APP=sso node index.js"
createdAt: "2017-02-02T05:29:56.392Z"
enabled: true
name: "Frank Command"
timeout: 180000
uri: "http://139.59.60.15/commands/5892c3d4d3128f231ab032bb"
私は私のテーブルにそれをレンダリングしたかったが、私は任意の助けがAPPRある
this.props.commands.map is not a function
のエラーを得ましたあなたに感謝します
を'this.state.commands.map'また、' this.props.commands.map'はJavascriptオブジェクトではないかもしれません。 'this.setState({commands:JSON.parse(this.props.commands)});' –
これは 'this.state.commands.mapは関数ではありません ' –
JSONで解析しようとしましたか?また、immutable.jsを使用しています –