我有一个显示可删除数据列表的表格。在该表格中,我有复选框供用户选择要删除的数据。当点击删除按钮时,将出现一个模态框,在该模态框中有一个带有ng-model的输入文本框。它的值将通过javascript/jquery设置。我希望使用angularjs $http请求将其删除。我观察到只有在文本字段中输入文本时才能正常工作。但是当通过javascript设置时,它不起作用。这是模态框内的输入字段。
<input class="form-control" id="id" ng-value="" ng-model="Thing.id" />
还有模态框:
<script type="text/javascript">
$('#delete_item').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var modal = $(this)
var ids=getID_delete.call();
$('.modal-body #id').val(ids) ;
modal.find('.modal-body #message').text('Are you sure you want to delete it?');
});</script>
下面是AngularJS控制器的代码:
mainApp.controller('equipmentController', ['$scope', '$http', function($scope, $http) {
$scope.equipments=[]
$http.get(BASE_URL+'Equipment/getAllEQs').success( function(response) {
$scope.equipments = response
});
$scope.delete = function(Thing) {
$params = $.param({
"id": Thing.id
})
return $http({
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
url:BASE_URL+'Equipment/DeleteEQ',
method: "POST",
data: $params,
})
.success(function(response) {
$('#delete_item').modal('hide');
$scope.equipments = response
});
}
}]);
delete(thing)
的代码吗?传到函数delete
的数据是正确的吗? - Abhilash Augustinealert(Thing.id)
时,结果是undefined
。但是当我手动输入数据到输入框中时,它可以正常工作。 - d_unknown