【发布时间】:2015-06-17 19:08:26
【问题描述】:
我对 angularjs 还很陌生。我正在尝试编辑 $scope.works 中的数据。我也尝试过 xeditable,但实际上并不能做太多事情。我知道这是一件简单的事情。但是你的回答真的很有帮助。谢谢。
这是我的代码 -
我的 angular.js 代码 -
$scope.works=[{id:'01', position:'web designer' ,place:'Artle' ,month:'April',year:'2014',month1:'April',year1:'2015',city:'delhi'},
{id:'02', position:'web designer' ,place:'Artle' ,month:'April',year:'2014',month1:'April',year1:'2015',city:'delhi'}];
$scope.editEnabled= false;
$scope.editData=function(work){
work.editEnabled = true;
};
$scope.saveData=function(data, id){
angular.extend(data, {id: id});
return $http.post('/saveData', data);
};
$scope.close=function(work){
work.editEnabled = false;
}
$scope.editEnabled = false;
$scope.disableEdit= function(){
$scope.editEnabled = false;
};
});
为了编辑和保存更改,我的 html 是-
<span ng-hide="work.editEnabled">
<button ng-click="editData(work) ">Edit</button>
</span>
<span ng-show="work.editEnabled">
<button ng-click="close(work);saveData($data, work.id); ">Save</button>
</script>
单击编辑时,我已在输入中显示了值。问题是,点击保存时输入中所做的新更改不会保存,它会在 $scope.works 中显示它
【问题讨论】:
-
请清理代码以仅包含必要的部分。
-
刚刚做到了。请再检查一遍
-
您是否在这里混淆了两个不同的东西,
work.editEnabled和$scope.editEnabled? -
不不,这很好用。我已经检查过了。问题出在 saveData 上。
标签: html angularjs angularjs-ng-repeat