Reactjs 如何在单击后立即重新渲染?

Reactjs 如何在单击后立即重新渲染?,reactjs,Reactjs,这里有一张桌子。其中我想删除行,只想看到当时的变化(表中删除了行)。我发现forceupdate()方法只需重新渲染即可完成此操作或更改状态,但这两种情况对我都不起作用 代码如下: var table = React.createClass({ getInitialState:function() { return { data:[] }; }, componentDidMount: function() { $.get('http://improw

这里有一张桌子。其中我想删除行,只想看到当时的变化(表中删除了行)。我发现
forceupdate()
方法只需重新渲染即可完成此操作或更改状态,但这两种情况对我都不起作用

代码如下:

var table = React.createClass({

  getInitialState:function() {
    return {
      data:[]
    };
  },
componentDidMount: function() {
    $.get('http://improwised.cgc.com/portfolios?token=yR225Y',
    function(result) {                    
      if (this.isMounted()) {
        this.setState({
          data: result.data,
        });
      }
    }.bind(this));
  },


  getComponent: function(Key) {

    $.ajax({
      type: "DELETE",
      url: "http://improwised.cgc.com/portfolios/"+Key+"?        token=yR225Y",
      //context: document.body
    })
  },


  render:function() {

    return (
      <div>
          <Table striped bordered condensed hover>
            <thead>
              <tr>

                <th>Name</th>
                <th>current_balance</th>
                <th>market_price</th>
                <th>profit/loss</th>
                <th>delete</th>

              </tr>
            </thead>
            <tbody>
              {
                this.state.data.map(function(data, index) {
                  return <tr>
                  <td><a href={'/#/portfolio/'+data.id}>{data.name}</a></td>
                  <td>{data.current_balance}</td>
                  <td></td>
                  <td></td>
                  <td><button value={data.id} onClick={this.getComponent.bind(this,data.id)}>delete</button></td>
                  </tr>
                }.bind(this))
              }

            </tbody>
          </Table>
        </div>
    );
  }
});
module.exports = table;
var table=React.createClass({
getInitialState:函数(){
返回{
数据:[]
};
},
componentDidMount:function(){
$.get('http://improwised.cgc.com/portfolios?token=yR225Y',
函数(结果){
if(this.isMounted()){
这是我的国家({
数据:result.data,
});
}
}.约束(这个);
},
getComponent:函数(键){
$.ajax({
键入:“删除”,
url:“http://improwised.cgc.com/portfolios/“+Key+”?令牌=yR225Y”,
//上下文:document.body
})
},
render:function(){
返回(
名称
当前余额
市场价格
盈亏
删除
{
this.state.data.map(函数(数据、索引){
返回
{data.current_balance}
删除
}.绑定(本)
}
);
}
});
module.exports=表格;

删除后需要设置新状态,如下所示

getComponent: function(Key) {
  $.ajax({
    type: "DELETE",
    url: "http://improwised.cgc.com/portfolios/" + Key + "?token=yR225Y",
  }).success(function () {
    var data = this.state.data.filter(function (e) {
      return e.id !== Key;
    });

    this.setState({ data: data });
  }.bind(this))
}