无法映射节点查询数据

时间:2018-03-06 21:07:18

标签: reactjs express

我设法通过我的节点服务器上的React获取数据,但是当我只是尝试映射它时。它告诉我,通过我的提取设置的状态不是一个功能。我在网上看,地图需要一个数组。但是,经过检查,我获得的承诺确实是一个阵列。

此外,我在我的服务器上使用必要的中间件,例如Bodyparser和CORS。

模型



app.post('/myForm/:orderNum', function(req, res){
    request.query("SELECT [eUId], [GuestName], [STAY] AS UnitNum, [DELIVERY DATE] AS Delivery, [MoveInDate] AS MoveIn, [ReservedByEMail] as SendTo FROM [Test_Database].[Orders].[Order] WHERE [TableId] = '"+ req.body.orderNum +"'", function(error, results, fields){
        if(error){
            throw error;
        } else {
            res.send(JSON.stringify(results));
        }
    });
    //console.log(req.body);
});




查看:



/*eslint-disable no-unused-vars*/

import React from 'react';
import ReactDOM from 'react-dom';

class Myform extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            errorMsg: "",
            orderNum: this.props.match.params.orderNum,
            theData: []
        }
    }

    componentWillMount(){
        var data = {
            orderNum: this.state.orderNum
        }

        fetch('/myForm/:orderNum', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(data)
        })
        .then(res => res.json())
        .then(theData => this.setState({theData: theData.recordset}));
    }

    render() {
        return (
            <div className="container">
            // Unable to map through the fetched data? this is where I'm stuck
            {/* {this.state.theData.map(theData =>
                <ul>
                    <li key={theData.id}>{theData}</li>
                </ul>
            )} */}
            </div>
        )
    }
}

export default MyForm;
&#13;
&#13;
&#13;

以下是我回复的承诺的屏幕截图,记录集是我尝试映射的内容。

enter image description here

0 个答案:

没有答案