【发布时间】:2016-06-11 22:38:13
【问题描述】:
在服务器上有代码
apiRoutes.put('/intake', function(req, res) {
Intake.findById({id, function(err, intake) {
if (err)
res.send(err);
check : true;
intake.save(function(err) {
if (err) {
return res.json({success: false, msg: 'Error'});
}
res.json({success: true, msg: 'Successful update check state.'});
});
}})
});
我应该从前端设置 ID 值,但我不知道如何在函数中设置它。试试这个 apiRoutes.put('/intake', id, function(req, res),但是没有定义 id 在 controller.js 的前面:
$scope.changeCheck = function(id) {
console.log(id);
mService.intake("PUT", $scope.intake, {"action": "put"}, id)
.success(function(data, status, headers, config) {
}).error(function(err) {
mService.errorHandler(status);
});
};
在服务文件中:
intake : function(method, data, params, value) {
var endpoint = "";
switch (params.action) {
case "put" :
endpoint = "intake/" + value;
break;
}
return this.request(method, endpoint, data);
}
html
<li ng-repeat="intake in intakes">
<div class="welcome-box">
<div class="welcome-box-content" >
<label class="checkbox">
<input type="checkbox" ng-model="intake.check" ng-change="changeCheck(intake.pres_id)" />
</label>
<span class="drugs"> {{intake.dname}} <br></span> <span class="drugsdescr"><i class="fa fa-comment" aria-hidden="true"> </i> {{intake.comment}} <i class="fa fa-medkit" aria-hidden="true"></i> {{intake.dose1}}{{intake.dose2}} </span>
</div>
</div>
</li>
获取摄入量
mService.intake("GET", "", {"action" : "get"})
.success(function(data, status, headers, config) {
$scope.intakes = data;
console.log(data);
})
.error(function(data, status, headers, config) {
mService.errorHandler(status);
});
【问题讨论】:
-
在你的控制器中调用 changeCheck 是什么?例如,它是按钮单击吗?你能展示那部分代码吗?
-
您的控制器中有进气口列表吗?你也可以添加你的控制器吗?
标签: javascript html angularjs node.js