我已经在这个项目上工作了一段时间。也许今天太多了,因为我的PUT方法有一个(很简单的)问题。
我有一个HTML表,其中包含一些包含布尔值的信息。
<tr ng-if="A.donepost == false" ng-repeat="A in author | filter: todofilter | orderBy:predicate:reverse">
<td>{{A.id}}</td>
<td ng-model="todoregistered">{{A.registered | date:'dd-MM-yyyy'}}</td>
<td ng-model="todoauthor">{{A.author}}</td>
<td ng-model="tododescription">{{A.description}}</td>
<td ng-model="tododeveloper">{{A.developer}}</td>
<td ng-model="todoinprogress">{{A.inprogress}}</td>
<!--<td>{{A.donepost}}</td>-->
<td>
<a href="#" ng-click="editTodo(A.id)" >edit </a> |
<a href="#" ng-click="deleteTodo(A.id)">delete</a> |
<a href="#" ng-click="DoneTodo(A.id)">done</a> |
<a ng-if="A.inprogress == false" href="#" ng-click="StartTodo(A.id)">Start</a>
</td>
</tr>
当&#34;开始&#34>时,此布尔值应更改为true。按下按钮。
我的http方法看起来像这样。
$scope.StartTodo = function (id) {
$scope.codingtodo = {
registered: $scope.todoregistered,
author: $scope.todoauthor,
description: $scope.tododescription,
developer: $scope.tododeveloper,
donepost: false,
$scope.author[id].inprogress: true
};
console.log(id)
console.log($scope.codingtodo)
$http({
method: 'PUT',
url: 'http://localhost:8080/api/resources/posts/' + id,
data: $scope.codingtodo, // Ive tried two things here
data: $scope.inprogress == true, // Ive tried two things here
console.log(data)
dataType: 'json'
}).success(function (data) {
$scope.todo.push(data);
console.log('Successfully started!');
$scope.error = null;
}).error(function (data, status) {
if (status == 401) {
$scope.error = "You are not authenticated to update these data";
return;
}
$scope.error = data;
});
};
我的怀疑是ng模型是愚蠢的。但正如我所说的那样,我已经连续工作了太多时间,所以我很善意地解决这个问题。
答案 0 :(得分:0)
我已经更改了HTML以获取整个Todo,而不是ID。 然后它奏效了。
<a ng-if="todo.inprogress == false" href="#" ng-click="StartTodo(todo)">Start</a>
然后我改变了JS。现在它翻了个懒。好的。
$scope.PauseTodo = function (todo) {
todo.inprogress = false;
$http({
method: 'PUT',
url: 'http://localhost:8080/api/resources/posts/' + todo.id,
data: todo,
dataType: 'json'
}).success(function (data) {
$scope.todo.push(data);
console.log('Successfully started!');
$scope.error = null;
}).error(function (data, status) {
if (status == 401) {
$scope.error = "You are not authenticated to update these data";
return;
}
$scope.error = data;
});
};