【发布时间】:2014-09-28 21:11:30
【问题描述】:
我在实现客户端更新 CRUD 逻辑时遇到问题。当前正在按照原样删除这些字段。我错过了什么?
我的角度:
$scope.editService = function(id) {
$http.put('/api/hc/' + id,
{title: 'new',
shortname: 'new',
summary: 'new',
description: 'new'}
)
.success(function(data) {
})
.error(function(data) {
console.log('Error: ' + data);
});
};
我的快递:似乎没有任何东西通过 JSON 值,由于某种原因,所有字段和键都被清除干净,只留下 _id 和 _v 键和值。
.put(function(req, res) {
Service.findById(req.params._id, function(err, service) {
if (err)
res.send(err);
service.title = req.body.title; // update the items info
service.summary = req.body.summary;
service.shortname = req.body.shortname;
service.description = req.body.description;
// save the items
service.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'Service updated!' });
});
});
})
我的看法
<form name="editForm" ng-submit="editService(service._id)" ng-repeat="service in services
filter:json">
<input type="text" placeholder="{{ service.title}}" ng-model="serviceTitle" required>
<input type="text" placeholder="{{ service.shortname}}" ng-model="serviceShortname" required>
<input type="text" placeholder="{{ service.description}}" ng-model="serviceSummary" required>
<textarea type="text" placeholder="{{ service.summary}}" ng-model="serviceDescription" required></textarea>
<button type="submit">Edit</button>
</form>
【问题讨论】:
标签: node.js angularjs express mean-stack