require('./SliderBox');
window.FullPage = React.createClass({
propTypes: {
items: React.PropTypes.object,
},
getInitialState:function(){
return{
layout : [],
items: []
}
},
leaveBox : function(){
var newItem = this.state.layout[this.state.index];
//ar newItems = this.state.items.push(newItem);
var newIndex = this.state.index + 1;
this.setState({items:this.state.items.concat(newItem) ,index : newIndex })
},
getLayout : function(){
$.ajax({
url:"url.com",
headers: { 'Access-Control-Allow-Origin': '*' },
type:'GET',
dataType: 'json',
crossDomain: true,
cache: false,
success: function(data) {
this.setState({layout: data});
this.setState({items :this.state.items.concat(data[0]), index: 1 })
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
componentWillMount:function(){
this.getLayout();
},
componentDidMount: function(){
},
loadMoreContents:function(){
var url = "SomeLink.com"
},
handleLeave : function(){
this.leaveBox();
},
render: function(){
var j = 1;
var k = 0;
if(this.state.index != 1){
var sliderItems = this.state.items.map(function(item){
return(
<div> <SliderBox key={item.position}
title={item.name}
url={ "url"
exit= {this.handleLeave.bind(this)}
first= {k}
/> </div> )
},this);
return(
<div> {sliderItems} </div>
)
}else {
if(this.state.layout.length > 0 ){
return(<div> <SliderBox key={this.state.layout[0].position}
title={this.state.layout[0].name}
url={ "url"}
exit= {this.handleLeave.bind(this)}
first= {j}
/>
</div>
)}else
{
return(<div></div>)
}
}
}
});
module.exports = FullPage;
所以基本上我的错误来自 this.setState ,请帮助谢谢。只有当我与 Rails 集成时才会出现遍历路径错误。它与正常反应完美配合。使用 react-rails 时会发生此错误