我无法应用从表格行中选择的数据的修改 [英] I can't apply the modification of my data selected from a table row
问题描述
当我尝试从表中修改行时,我的代码出现问题,我使用AngularJS作为客户端,ASP.Net作为其余API,这是我的HTML代码:
< table ng-controller = etudmodifCtrl >
< ; thead >
< / thead >
< tbody >
< tr ng-repeat = 在currentPageStores中存储>
< td align = center > {{store。 LastName}} < / td >
< td align = center > {{store.FirstName}} < / td >
< td align = center > {{store.Email}} < / td >
< td 对齐 = center > {{store.Id}} < / td >
< td align = center ng-controller < span class =code-keyword> = etuddeleteCtrl >
< div id = myModal class = 模态淡化 角色 = 对话框 >
< div class = modal-dialog < span class =code-keyword>>
< div class = 模态内容 >
< div class = modal-header > .... < / div >
< div class = modal -body >
< div class = form-group >
< label > LastName < / label >
< div class = col -sm-10 >
< input 类型 = text class = form-control ng-model = nomet >
< / div >
< / div >
< div c lass = form-group > ;
< label > FirstName < / label > ;
< div class = col-sm-10 >
< 输入 类型 = text class = 表格 - control ng-model = prenomet >
< / div >
< / div >
< div class = form-group >
< label > 电子邮件< / label >
< div class = col-sm-10 >
< 输入 类型 = text class = form-control ng-model = 电子邮件 >
< / div >
< / div >
< span class =code-keyword>< / div >
//单击此按钮将应用修改
< div class = 模态躯跨度> <跨度class =code-keyword>>
< 按钮 < span class =code-attribute> id = button data-dismiss = modal > 确定 < / button >
< / div >
< / div >
< / div >
//此按钮打开我将修改数据的模式
< 按钮 ng-click < span class =code-keyword> = open(store.Id) data-target = #myModal > 修改< / button < span class =code-keyword>>
< / td >
< / tr > < / tbody > < < span class =code-leadattribute> / table >
这是控制器:
.controller(etudmodifCtrl,[$ scope,$ http, logger,$ route,函数($ scope,$ http,logger,$ route){
$ scope.errors = [];
$ scope.msgs = [];
$ scope.open = function(Id){
console.log(ID open ---);
console.log(Id);
$ http({method:'GET',url:'http:// localhost:50001 / api / Students /'+ Id})
.success(function(data){
$ scope.errors.splice(0,$ scope.errors.length); //删除所有错误消息
$ scope.msgs.splice(0,$ scope.msgs.length);
$ scope.prenomet = data.FirstName;
$ scope.nomet = data.LastName;
$ scope.email = data.Email;
console.log(成功显示) ;
document.getElementById('button')。onclick = function(){
console.log(IDaprèsmodifetud---);
console.log( Id);
$ http({method:'PUT',
url:'http:// loc alhost:50001 / api / Students / modifier /'+ Id,
header:{'Content-Type':'application / json'},
data:'{FirstName:'+ $ scope.prenomet +',LastName:'+ $ scope.nomet +',电子邮件:'+ $ scope.email +'}'
}
)
.success(function(){
console.log(----- success -----+ Id);
console.log($ scope.prenomet ++ $ scope.nomet ++ $ scope.email);
logger.logSuccess(etudiantaétémodifiéavecsuccès);
})。error(function(){
logger.logError(echec de modification de l'étudiant);
console.log(data错误...);
});
}
})。error(函数(data,status,headers,config){
console.log(data error ...);
});
}}])
每个例子如果我用Id选择表格行= 6我正确输入表格中的数据,但是当我尝试修改输入数据然后在确定按钮上输入时,我总是得到旧数据而不是修改后的数据
with
Id = 6,$ scope.prenomet = Student6,$ scope.nomet = 6,$ scope.email = student6 @ yahoo.com(没有修改),如果我将此数据修改为scope.prenomet = Student66,$ scope.nomet = 66,$ scope.email = student66 @ yahoo.com
我在控制台上得到这个:
ID打开---
6
成功显示
IDaprèsmodifetud---
6
-----成功----- 6
Student6 6 student6@yahoo.com
成功
请你对这个问题有所了解,非常感谢你帮忙
scope,
http, logger,
route,功能(
Hi,
I have problem in my code when I try to modify a row from a table, I work with AngularJS as client and ASP.Net as the rest API, this is my HTML code :
<table ng-controller="etudmodifCtrl">
<thead>
</thead>
<tbody >
<tr ng-repeat="store in currentPageStores>
<td align="center">{{store.LastName}}</td>
<td align="center">{{store.FirstName}}</td>
<td align="center">{{store.Email}}</td>
<td align="center" >{{store.Id}}</td>
<td align="center" ng-controller="etuddeleteCtrl">
<div id="myModal" class="modal fade" role="dialog" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">....</div>
<div class="modal-body">
<div class="form-group">
<label>LastName</label>
<div class="col-sm-10">
<input type="text" class="form-control" ng-model="nomet">
</div>
</div>
<div class="form-group">
<label>FirstName</label>
<div class="col-sm-10">
<input type="text" class="form-control" ng-model="prenomet">
</div>
</div>
<div class="form-group">
<label>Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" ng-model="email">
</div>
</div>
</div>
//click on this button will apply the modification
<div class="modal-footer">
<button id="button" data-dismiss="modal">OK</button>
</div>
</div>
</div>
//this button opens the modal in which I will modify the data
<button ng-click="open(store.Id)" data-target="#myModal">Modify</button>
</td>
</tr></tbody></table>
and this is the controller:
.controller("etudmodifCtrl", ["$scope", "$http", "logger","$route", function ($scope, $http, logger,$route) { $scope.errors = []; $scope.msgs = []; $scope.open = function (Id) { console.log("ID open---"); console.log(Id); $http({method: 'GET', url: 'http://localhost:50001/api/Students/'+Id}) .success(function (data) { $scope.errors.splice(0, $scope.errors.length); // remove all error messages $scope.msgs.splice(0, $scope.msgs.length); $scope.prenomet=data.FirstName; $scope.nomet=data.LastName; $scope.email=data.Email; console.log("success display"); document.getElementById('button').onclick = function() { console.log("ID après modifetud---"); console.log(Id); $http({method: 'PUT', url:'http://localhost:50001/api/Students/modifier/'+Id, headers: {'Content-Type': 'application/json'}, data:'{"FirstName":"'+$scope.prenomet+'","LastName":"'+$scope.nomet+'","Email":"'+$scope.email+'"}' } ) .success(function () { console.log("-----success-----"+Id); console.log($scope.prenomet+" "+$scope.nomet+" "+$scope.email); logger.logSuccess("etudiant a été modifié avec succès"); }).error(function () { logger.logError("echec de modification de l'étudiant"); console.log("data error ..."); }); } }).error(function (data, status, headers, config) { console.log("data error ..."); }); }}])
Per example If I select the row of table with Id=6 I get correctly the data in the input forms,but when I try to modify the input data then clic on the "OK" button I get always the old data not the modifed one
with
Id=6,and $scope.prenomet=Student6,$scope.nomet=6,$scope.email=student6@yahoo.com(without modifcation),if I modify this data to scope.prenomet=Student66,$scope.nomet=66,$scope.email=student66@yahoo.com
I get this on console:
ID open---
6
success display
ID après modifetud---
6
-----success-----6
Student6 6 student6@yahoo.com
success
have you any idea please about the problem,thanks a lot for help
scope", "
http", "logger","
route", function (
这篇关于我无法应用从表格行中选择的数据的修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!