Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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
Javascript 当我将JSON对象体系结构传递到客户端时,它看起来不同_Javascript_Json_Mongodb_Mongoose_Electron - Fatal编程技术网

Javascript 当我将JSON对象体系结构传递到客户端时,它看起来不同

Javascript 当我将JSON对象体系结构传递到客户端时,它看起来不同,javascript,json,mongodb,mongoose,electron,Javascript,Json,Mongodb,Mongoose,Electron,这是我的模式 var mongoose = require('mongoose'); var Schema = mongoose.Schema; var messageSchema = new Schema({ requestNumber: String, requestedDateTime: String, reasons: String, state: String, hospital: String, phone:

这是我的模式

var mongoose     = require('mongoose');
var Schema       = mongoose.Schema;

var messageSchema   = new Schema({
    requestNumber: String,
    requestedDateTime: String,
    reasons: String,
    state: String,
    hospital: String,
    phone: String,
    status: {type: String, default: 'Pending'},
    latestUpdate: Date,
    createdAt: {type: Date, default: Date.now}
});

module.exports = mongoose.model('Requests', messageSchema);
下面我将返回包含三个组件的集合

ipcMain.on('load-requests', function(event) {

  hosSchemaModel.find(function(err, hosSchema) {
        if (err) {
          console.log('inside error') // return res.send(err);
        } else {

          event.sender.send('requests-results', hosSchema) // this line of code passes hosSchema to the client side

          console.log(hosSchema[0].state) //prints the state attribute of the first component in the collection without any errors.

        }
    });
});
当我尝试在服务器中
console.log(hosSchema)
时,会将以下内容打印到终端:

通过引用集合中第一个组件的索引
hosSchema[0]。status
,我可以成功访问属性,例如集合中第一个组件的状态

下面我正在尝试将
hosSchema
打印到控制台(在前端)

我得到的结果与他们在终点站看到的不同。下面是图片

hosSchema[0]。状态
返回未定义

我的问题是:

1) 为什么
hosSchema[0]。状态在前端不起作用


2) 访问客户端中属性的正确方法是什么?

前端需要做的就是使用
hosSchema[0]。\u doc.status
而不是
hosSchema[0]。status

ipcRenderer.on('requests-results', (event, hosSchema) => {
    console.log(hosSchema)
  })