【发布时间】:2014-02-09 20:16:19
【问题描述】:
我有编辑一些模型的管理页面。当我得到模型时,我将其转换为 JSON 并得到如下内容:
{
"__v": 0,
"_id": "52d919c7ec31cffc17477767",
"description": "Hello, teached",
"points": 1300,
}
这是我的玉模板
form(role='form', method='post', action='/admin/item')
.form-group
textarea.form-control#result(rows='20', name='result') !{JSON.stringify(item, null, '\t')}
input.btn.btn-primary(type='submit', value='Send')
这是我的路由器代码
app.post('/admin/item', function (req, res) {
result = JSON.parse(req.body.result);
Item.update({_id: result._id}, result, function (err, result) {
if (err) {
res.send('error');
} else {
res.send(result, 200);
}
});
});
而且我总是得到一个错误,但是当我手动更新每个字段时,像这样:
result = JSON.parse(req.body.result);
Item.update({_id: result._id}, {description: result.description, ...
它神奇地更新。我做错了什么?
【问题讨论】:
标签: json node.js express mongoose