0

この反応コードでは、データを現在の状態に設定しようとしています。データを状態に設定した後、固定データ テーブルで使用する必要があります。それを実現するには、以下のように記述しました。主な問題は、" this.setState " のcomponentDidMountが実行されていないか、そこでデータ テーブル関数を呼び出す必要がある場所に到達していません。ここに私のコードがあります:

     export default class Main extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                result: [],
                loading: false,
                filteredRows: null,
                filterBy: null,
            };
        }
        getZipData() {
            //Here i got the data from server 
        }
        componentDidMount() {
            this.getZipData().then((data)=>{
                console.log("data:"+data.length);
                this.setState({result:data,loading:true});  //state successfully set here.
                console.log("result:*******************"+this.state.result.length); //this console is not printed
this._filterRowsBy(this.state.filterBy)
            });

        };
        _rowGetter(rowIndex){
            alert("row Getter");
            return this.state.filteredRows[rowIndex];
        }
        _filterRowsBy(filterBy){
            var rows = this.state.result.slice();
            var filteredRows = filterBy ? rows.filter((row)=>{
                return row.RecNo.toLowerCase().indexOf(filterBy.toLowerCase()) >= 0
            }) : rows;
            this.setState({
                filterRows,
                filterBy,
            })
        }
        _onFilterChange(e){
            this._filterRowsBy(e.target.value);
        }
        render() {
            if(this.state.loading==false) {
                return (
                    <div className="row-fluid">
                        <img className="col-sm-6 col-sm-offset-3 col-xs-6 col-xs-offset-3"
                             src="http://www.preciseleads.com/images/loading_animation.gif"/>
                    </div>
                )
            }
            else{
                console.log("result:////////////////////"+this.state.result.length); //this console is printed
                console.log("loading completed");
                return(
                    <div>
                       <!-- fixed data table code goes here -->
                    </div>
                )
            }

        }
    }

状態は正常に更新されましたが、そのステートメントに達しなかった後、 IN componentDidMount、どんな助けも大歓迎です。

4

2 に答える 2