react.js - react-bootstrap表格组件,onSelect方法更新数据
本文介绍了react.js - react-bootstrap表格组件,onSelect方法更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
分页组件:
<Pagination prev next boundaryLinks
items={this.state.pager.all_page}
maxButtons={10}
bsSize="small"
activePage={this.state.pager.page}
onSelect={this.Pagination}
/>
其中onSelect方法官方文档是一个函数,我想在点击页码或者分页时想后端拉取数据,然后更新state,但是报setState is not a function,console一下this确实没有这个方法,所以现在该怎样更新我的数据呢?
Pagination(event){
//event为点击分页页码的数字可以拿到
var $this = this;
$.ajax({
url:'/api/。。。',
type: 'GET',
dataType: 'json',
data: {
pager: event
},
success: function(map){
$this.setState({
data: map.data.data,
pager: map.data.pager
})
}
})
}
现在问题不单单是一个组件的setState方法报错,还有其他的组件这个方法报错
constructor(props){
super(props);
this.state = {
city: [],
area: [],
community: []
}
}
SelectCity(event){
var $this = this;
$.ajax({
url:'/api/....',
type: 'GET',
dataType: 'json',
data: {
city_id : event.target.value
},
success: function(map){
$this.setState({
area : map.data
});
}
})
}
也是一样的错误$this.setState is not a function。
求大神讲解
解决方案
问题已解决,还是es6不熟
onChange={(event) => {$this.SelectCity(event)}}
组件内部onChane方法如上写法即可
这篇关于react.js - react-bootstrap表格组件,onSelect方法更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文