还绑定回调函数,以便
this回调内部指向React Component的上下文,而不是回调函数
getPosts = () => { $.ajax({ type: 'get', url: urlname, success: (data) => { this.setState( { posts: data } ) } });}或者你可以像这样使用bind
getPosts = () => { $.ajax({ type: 'get', url: urlname, success: function(data) { this.setState({ posts: data }) }.bind(this) });}


