变量在javascript中不被识别为变量(Variable not being recognized as variable in javascript)
有人能够在下面的代码中告诉我我错在哪里吗? 出于某种原因,'contact.name'中的第一个'联系人'看不到变量。
var newContact = new Contact({ contact.name = req.body.name, contact.email = req.body.email, contact.number = req.body.number });Would someone be able to tell me where I am wrong in the following code? For some reason the first 'contact' in 'contact.name' is not seen a variable.
var newContact = new Contact({ contact.name = req.body.name, contact.email = req.body.email, contact.number = req.body.number });最满意答案
你想做这样的事吗?
var newContact = new Contact({ contact: { name: req.body.name, email: req.body.email, number: req.body.number } });我们需要了解有关Contact类构造函数及其参数的更多信息,以确保传递的参数的格式正确。
拥有这样的参数实际上更有意义:
var newContact = new Contact({ name: req.body.name, email: req.body.email, number: req.body.number });Did you want to do something like this?
var newContact = new Contact({ contact: { name: req.body.name, email: req.body.email, number: req.body.number } });We need to know more about the Contact class constructor and its parameters in order to make sure that the passed arguments are in the correct form.
It would actually make more sense to have the arguments like this:
var newContact = new Contact({ name: req.body.name, email: req.body.email, number: req.body.number });更多推荐
发布评论