Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.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 为什么这个子对象是空的,不管我做什么?_Javascript_Reactjs_Meteor_Meteor Collection2 - Fatal编程技术网

Javascript 为什么这个子对象是空的,不管我做什么?

Javascript 为什么这个子对象是空的,不管我做什么?,javascript,reactjs,meteor,meteor-collection2,Javascript,Reactjs,Meteor,Meteor Collection2,这件事让我头疼得流鼻血 尝试: Reservation.insert(this.state); const res=/手动设置每个字段 const res=//手动设置每个字段以及设置停车场字段,如代码中所示 我不知道我还能尝试什么,公园总是空荡荡的。这将导致在尝试插入时出错 完整功能如下: handleSubmit(事件,$){ event.preventDefault(); 常数res={ 日期:新日期(), 停车场:{ _身份证:这个。州。停车场, 编号:this.state.parki

这件事让我头疼得流鼻血

尝试:

Reservation.insert(this.state);
const res=/
手动设置每个字段

const res=//
手动设置每个字段以及设置停车场字段,如代码中所示

我不知道我还能尝试什么,公园总是空荡荡的。这将导致在尝试插入时出错

完整功能如下:
handleSubmit(事件,$){
event.preventDefault();
常数res={
日期:新日期(),
停车场:{
_身份证:这个。州。停车场,
编号:this.state.parkingLot.number,
名称:this.state.parkingLot.name,
描述:this.state.parkingLot.description,
价格:this.state.parkingLot.price,
保留:this.state.parkingLot.reserved,
},
用户:$.state.user,
开始:$.state.begin,
结束:$.state.end,
};
console.log('Submit',res,this.state);
保留。插入(res);
}
我尝试了以下方法:

 <script>
  const res = {
    date: new Date(),
    parkingLot: {
      _id: 11,
      number: 12,
      name: 'jhon',
      description: 'j',
      price: 3232,
      reserved: true,
    },
    user: 'j',
    begin: 'j',
    end: 'j',
  };

console.log(res);
</script>

常数res={
日期:新日期(),
停车场:{
_id:11,
编号:12,
姓名:“jhon”,
描述:'j',
价格:3232,
是的,
},
用户:“j”,
开始:“j”,
完:"j",,
};
控制台日志(res);
而且它工作得很好。 你确定所有的财产都在那里吗?尝试在控制台中调试它。 “this.state.parkingLot.\u id”确实返回了一个数字吗?

我试过:

 <script>
  const res = {
    date: new Date(),
    parkingLot: {
      _id: 11,
      number: 12,
      name: 'jhon',
      description: 'j',
      price: 3232,
      reserved: true,
    },
    user: 'j',
    begin: 'j',
    end: 'j',
  };

console.log(res);
</script>

常数res={
日期:新日期(),
停车场:{
_id:11,
编号:12,
姓名:“jhon”,
描述:'j',
价格:3232,
是的,
},
用户:“j”,
开始:“j”,
完:"j",,
};
控制台日志(res);
而且它工作得很好。 你确定所有的财产都在那里吗?尝试在控制台中调试它。
“this.state.parkingLot.\u id”是否实际返回一个数字?

您是否在组件构造函数中绑定了
this

class MyComponent extends React.Component {
  constructor(props) {
    super(props)

    this.handleSubmit = this.handleSubmit.bind(this)
  }

  handleSubmit(evt) {
   ...
  }
}
或者,您可以使用类属性并将事件处理程序声明为箭头函数。为此,你需要巴贝尔插件


还要看一看:

您是否在组件构造函数中绑定了此

class MyComponent extends React.Component {
  constructor(props) {
    super(props)

    this.handleSubmit = this.handleSubmit.bind(this)
  }

  handleSubmit(evt) {
   ...
  }
}
或者,您可以使用类属性并将事件处理程序声明为箭头函数。为此,你需要巴贝尔插件


还可以查看:

停车场已设置为状态。我通过console.log(this.state)检查过,您是否有其他想法,它可能是什么?可能是在事件处理程序运行时,还没有状态。你能显示组件的完整代码吗?我添加了我的代码,虽然我更改了代码以保存停车场的Id,但仍然有效。因此,当我获得预订时,我正在加载引用的停车场。停车场设置为状态。我通过console.log(this.state)检查过,您是否有其他想法,它可能是什么?可能是在事件处理程序运行时,还没有状态。你能显示组件的完整代码吗?我添加了我的代码,虽然我更改了代码以保存停车场的Id,但仍然有效。所以我在预订时正在加载参考停车场。