我想使用node-zillow模块来设置lastSoldDate的值,但是当我发布时,我得到错误lastSoldDate是不确定的。这是我到目前为止的内容:
router.route('/add').post((req, res) => {
const address = req.body.address
const street = address.street
const zipcode = address.zipcode
const city = address.city
const state = address.state
paramaters = {
address: address.street,
citystatezip: address.city + ", " + address.state
}
zillow.get('GetDeepSearchResults', paramaters)
.then(function(results) {
date = results.response.results.result[0].lastSoldDate[0]
console.log(date)
return date;
}).then((date) => lastSoldDate = date)
const lastSoldPrice = req.body.lastSoldPrice
const newProperty = new property({
address:{
street,
zipcode,
city,
state,
},
lastSoldDate,
lastSoldPrice
})
newProperty.save()
.then(() => res.json('Property added!'))
.catch(err => res.status(400).json('Error: ' + err))
})