我在React中构建组件。在我尝试循环遍历一个状态之前,一切似乎都很完美。反应:在状态中循环访问数组
这是我的组分:
var BidItem = React.createClass({
getInitialState: function() {
return {
theMaxBid: '',
theHighestBids: ''
};
},
componentDidMount: function() {
var $component = this;
$.ajax({
type : "post",
dataType : "json",
url : myAjax.ajaxurl,
data : {action: "get_max_bid"},
})
.done(
function(response){
$component.setState({
theMaxBid: response.max_bid,
theHighestBids: response.highest_bids
});
}
);
},
render: function() {
var dd = [{ids:"2"}, {ids:"5"}];
var cc = this.state.theHighestBids;
console.log(cc);
console.log(dd);
return (
<div>
<p>Max Bid: {this.state.theMaxBid}</p>
</div>
)
}
});
这工作,并在渲染功能CC和DD输出阵列看起来像:
当我循环通过CC数组(来自状态)在渲染函数内:
{cc.map(function(result){
console.log(result);
})}
我得到以下错误:
Uncaught TypeError: cc.map is not a function
但是当我通过下面的DD阵列环,它的工作原理:
{dd.map(function(result){
console.log(result);
})}
我为什么不能循环状态数组?