【发布时间】:2016-03-24 08:52:16
【问题描述】:
我尝试使用 angularjs 和 php api 制作简单的 CRUD 问题出在angularjs中
我有这样的代码:
$scope.editData = function(pid) {
$scope.hideform = false;
$scope.edit = false;
$scope.pid = $scope.projects[pid].pid;
$scope.title = $scope.projects[pid].title;
$scope.pcode = $scope.projects[pid].pcode;
$scope.type = $scope.projects[pid].type;
$scope.proj_type = $scope.projects[pid].proj_type;
};
$scope.saveData = function(pid, title, pcode, type2, proj_type){
$http.post("api/getProject.php",
{type: "edit", id:pid, title:title, pcode:pcode, type2:type2, proj_type:proj_type})
.success(function(data) {
notification(data.success, data.message);
$scope.hideform = true;
});
};
并具有用于编辑数据的表单(单击编辑按钮,然后显示加载了 ng-model 的表单编辑
喜欢这个
<form class="form-horizontal" ng-hide="hideform" ng-submit="saveData(pid,title, pcode, type, proj_type)">
<h3 ng-hide="edit">Edit Project:</h3>
<div class="form-group">
<label class="col-sm-2 control-label">PID:</label>
<div class="col-sm-10">
<input type="text" ng-model="pid" ng-disabled="!edit" placeholder="PID">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Title:</label>
<div class="col-sm-10">
<input type="text" ng-model="title" placeholder="Title">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Pcode:</label>
<div class="col-sm-10">
<input type="text" ng-model="pcode" placeholder="Pcode">
</div>
</div>
<button class="btn btn-success" ng-disabled="error || incomplete">
<span class="glyphicon glyphicon-save"></span> Save Changes
</button>
</form>
脚本正在运行,但是每次我单击保存编辑然后单击编辑按钮(在表格的每一行上),表单输入上的 ng-model 仍然与我保存的最后一个数据相同,但其他输入已更改,例如:我编辑了标题,当点击表格不同行上的编辑按钮时,只需将 pcode 更改为不同的行数据,标题仍然与我编辑的最后一个数据相同 对不起,如果我的解释让大家感到困惑 任何帮助将不胜感激
【问题讨论】:
-
我没有正确理解您的问题。 “保存更改”是否正常工作?此外,您还必须在保存数据后以角度更新您的项目数组
-
保存更改工作正常,但 ng-model 没有刷新,如您在图片中看到的那样,我保存更改后标题没有改变 TestingBABIBUS 然后单击 Testing3 行上的编辑 :)