Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 节点JS | TypeError:无法读取属性';p#u nome';未定义的_Node.js_Reactjs - Fatal编程技术网

Node.js 节点JS | TypeError:无法读取属性';p#u nome';未定义的

Node.js 节点JS | TypeError:无法读取属性';p#u nome';未定义的,node.js,reactjs,Node.js,Reactjs,下午好,我是react和node.js的新手,我有一个问题 我在网页上有一个表格,你可以在那里收到旅行的数据。列(Id locales、name、date、time)出现在旅行订单模型中,但列“localities name”用于列出使用Id的地点名称。此地点的Id列在“localities Id”列中。但是,在列出时,它给了我一个错误:“TypeError:无法读取未定义的属性'designaco' 为了更好地理解表格,在第一行数据中,1是出发id,124是到达id。我上传了表格以及控制器和模

下午好,我是react和node.js的新手,我有一个问题

我在网页上有一个表格,你可以在那里收到旅行的数据。列(Id locales、name、date、time)出现在旅行订单模型中,但列“localities name”用于列出使用Id的地点名称。此地点的Id列在“localities Id”列中。但是,在列出时,它给了我一个错误:“TypeError:无法读取未定义的属性'designaco'

为了更好地理解表格,在第一行数据中,1是出发id,124是到达id。我上传了表格以及控制器和模型的照片

表中数据的插入是在函数
loadFillData()
中完成的,该函数在以下代码中提供:

import React from 'react';
import '../../../assets/css/Pagamentos.css'
import 'js-datepicker/dist/datepicker.min.css';
import '../../../assets/css/bootstrap.css';
import axios from 'axios';
import { data } from 'jquery';
const datepicker = require('js-datepicker');

class Pagina extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            pag_pendentes: []
        }
    }

    componentDidMount() {
        const picker = datepicker('#calendario', {
            formatter: (input, date, instance) => {
                input.value = new Intl.DateTimeFormat('en-GB').format(date)
            }
        });

        const url = "http://localhost:3001/operadora/pendente";
        axios.get(url)
        .then(res=>{
            if(res.data.success){
                const data = res.data.data;
                this.setState({pag_pendentes:data});
            }else{
                alert("Erro");
            }
        })
        .catch(error=>{
            alert(error)
        });
    }

    render() {
        return (
            <div>
                <div id="div-filtragem">
                    <label className="Label_DatePicker">Data inicio:</label>
                    <input placeholder="Selecione uma data" type="text" id="calendario" className="form-control DatePicker datepicker" style={{ width: "auto" }} />
                    <label className="Label_DatePicker">Data fim:</label>
                    <input placeholder="Selecione uma data" type="text" id="calendario" className="form-control DatePicker datepicker" style={{ width: "auto" }} />
                    <button type="button" className="ButtonFilter ">Filtrar</button>
                </div>
                <div className="div_tabela">

                    <table className="table tabela" >
                        <thead>
                            <tr>
                                <th scope="col">IDs localidades</th>
                                <th scope ="col">nome localidades</th>
                                <th scope="col">Nome</th>
                                <th scope="col">Data</th>
                                <th scope="col">Hora</th>
                                <th scope="col">Valor</th>
                            </tr>
                        </thead>
                        <tbody>
                            
                            {this.loadFillData()}
                        </tbody>
                    </table>
                </div>
            </div>
        );
    }
    loadFillData(){
        console.log(this.state.pag_pendentes);
        return this.state.pag_pendentes.map((data, index) => {
            
            return (
                <tr key ={index}>
                    <td className="td_viagem">{data.partida + "-"+data.chegada}</td>
                    <td>{data.pp.designacao + "-"+data.pc.designacao}</td>
                    <td>{data.pessoa.p_nome + " " +data.pessoa.u_nome}</td>
                    <td>{data.data_viagem}</td>
                    <td>{data.hora_viagem}</td>
                    <td>10€</td>
                </tr>

            )
        });
    }
}

export default Pagina;
pedido_viagem型号:

var Sequelize = require('sequelize');
var sequelize = require('./database');
var Municipe = require('./pessoa');
var Estado  = require('./estado_pedido');
var Partida  = require('./freguesias');
var Chegada  = require('./freguesias');


var pedido_viagem = sequelize.define('pedido_viagem',{
    id:{
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },
    municipe:{
        type: Sequelize.INTEGER,
        references:{
            model:Municipe,
            key:'id'
        },
        allowNull:false  // coloca variável NOT NULL
    },

    partida:{
        type: Sequelize.INTEGER,
        references:{
            model:Partida,
            key:'id'
        },
        allowNull:false  // coloca variável NOT NULL
    },
    chegada:{
        type: Sequelize.INTEGER,
        references:{
            model:Chegada,
            key:'id'
        },
        allowNull:false  // coloca variável NOT NULL
    },
    data_viagem: {
        type:Sequelize.DATE,
        allowNull:false  // coloca variável NOT NULL
    },
    hora_viagem:{
        type:Sequelize.TIME,
        allowNull:false  // coloca variável NOT NULL
    },
    aceita_partilha:{
        type:Sequelize.INTEGER,
        allowNull:false  // coloca variável NOT NULL
    },
    necessidades_especiais: {
        type:Sequelize.INTEGER,
        allowNull:false  // coloca variável NOT NULL
    },
    bagagem: {
        type:Sequelize.INTEGER,
        allowNull:false  // coloca variável NOT NULL
    },
    estado:{
        type:Sequelize.INTEGER,
        references:{
            model: Estado,
            key:'id'
        }
    }
},
{
    timestamps: false,
    freezeTableName: true
});

pedido_viagem.belongsTo(Municipe,{foreignKey:'municipe'});
pedido_viagem.belongsTo(Partida,{as:'pp',foreignKey:'partida'});
pedido_viagem.belongsTo(Chegada,{as:'pc',foreignKey:'chegada'});

module.exports= pedido_viagem;
弗赖奎亚斯型号:

var Sequelize = require('sequelize');
var sequelize = require('./database');
var tipo_freguesia = require('./tipo_frequesia');;

var freguesia = sequelize.define('freguesias',{
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    designacao: {
         type:Sequelize.CHAR(50),
         allowNull:false  // coloca variável NOT NULL
    },   
    localizacao: {
        type: Sequelize.CHAR(100),
        allowNull:false // coloca variável NOT NULL
    },
    zona: {
        type:Sequelize.INTEGER,
        allowNull:false  // coloca variável NOT NULL
    },
    tipo_freguesia:{
        type: Sequelize.INTEGER,
        regerences:{
            model:tipo_freguesia,
            key:'id'
        },
        allowNull:false  // coloca variável NOT NULL
    }
},
{
 timestamps: false,
 freezeTableName: true,
});

module.exports = freguesia;
日志文件:

Node.js日志:

请,如果有人能帮助我,非常感谢。我是一个初学者,我不明白为什么我会犯这个错误

大家好。

问题在于:

include: [Viagem],
        include: [Estado], 
        include:[{
                model: Partida,
                as:'pp',
                attributes:['designacao']
            },
            {model: Chegada, 
                as:'pc',
                attributes:['designacao']}],
        include: [{
            model: Pessoa,
            attributes:['p_nome', 'u_nome']}]
您正在覆盖
include
,它将解析为仅使用最后一个,而应将include用作数组:

include: [Viagem,  Estado, {
                model: Partida,
                as:'pp',
                attributes:['designacao']
            },
            {model: Chegada, 
                as:'pc',
                attributes:['designacao']},  {
            model: Pessoa,
            attributes:['p_nome', 'u_nome']}]


你能提供console.log(this.state.pag_pendentes)的输出吗?显示所有内容,但不显示partida和chegadaThank you,byt现在显示此问题类型错误:this.state.pag_pendentes.map不是一个函数您可以记录axios响应并告诉我其中的内容吗?我很抱歉。我是react和node.js的初学者。我该怎么做呢?只要把:`console.log(res)`after'。然后(res=>{'行,然后打开浏览器控制台,查看记录的值。我把log放在这个问题上
include: [Viagem,  Estado, {
                model: Partida,
                as:'pp',
                attributes:['designacao']
            },
            {model: Chegada, 
                as:'pc',
                attributes:['designacao']},  {
            model: Pessoa,
            attributes:['p_nome', 'u_nome']}]