我是angular js的新手,我正在尝试编写一个简单的待办事项列表应用程序,我可以在其中更新任务。每当我点击编辑按钮时,文本框就会启用编辑,我会通过HTTP请求向服务器发送一个新值,但我无法获得角度js中的新值。
这是我的HTML代码:
<tr data-ng-repeat="user in tasks.tasks">
<td> // user.uid // </td>
<td > <input type="text" id="ddd" name="updatedText" ng-model="user.taskname" ng-disabled="!disable" value="//user.taskname//">
<input type="image" ng-hide="okbtnstatus" ng-click="updateIt()" src="static/img/okbtn.png" height="15px" width="18px" name="editId" value="//user.uid//">
这是我的角色代码
$scope.updateIt = function(){
var data = $scope.user.taskname
alert(data)
$http({
method: "PUT",
url:"item/"+data
}).then(function mySuccess(response){
alert("Updated!!!")
},
function myError(response){
alert("error occurred")
});
}
这里我没有得到数据变量的更新值。请帮忙。
答案 0 :(得分:0)
我们无法看到您的代码$scope.user
中的位置,但绝对会显示所选的user
。
<tr data-ng-repeat="user in tasks.tasks">
<td> // user.uid // </td>
<td> <input type="button" ng-click="updateIt(user)" value="//user.uid//"/> </td>
</tr>
该功能将接收用户
$scope.updateIt = function(user){
var data = user.taskname;
alert(data);
}
在我们使用var data = user.taskname;
的函数中,使用$scope.user.taskname
会产生意想不到的结果,因为我们无法看到$scope.user
的设置位置。
希望它能帮助你走上正确的道路。