我有一个包含多个列和行的表。我已经为每一行提供了一个删除按钮。如何从此表中删除整行?
我的控制器
;
(function () {
'use strict';
angular.module('app', []).controller('questionEditCtrl', ['$scope', '$timeout', '$http', function ($scope, $timeout, $http) {
$scope.delete = function () {
console.log("submit pressed");
}
}]);
})();
我的观点
<div class="container" ng-controller="questionEditCtrl">
<form class="form-horizontal" role="form" name='quizEdit' ng-submit="submit(data)">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Questions</th>
<th>Answer 1</th>
<th>Answer 2</th>
<th>Answer 3</th>
<th>Answer 4</th>
<th>Answer 5</th>
<th>Correct Answer</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
foreach ($quizes as $q) {
?>
<tr>
<td><?php echo $q['question_id']; ?></td>
<td><?php echo $q['question']; ?></td>
<td><?php
if (isset($q['answers'][0])) {
echo $q['answers'][0];
}
?></td>
<td><?php
if (isset($q['answers'][1])) {
echo $q['answers'][1];
}
?></td>
<td><?php
if (isset($q['answers'][2])) {
echo $q['answers'][2];
}
?></td>
<td><?php
if (isset($q['answers'][3])) {
echo $q['answers'][3];
}
?></td>
<td><?php
if (isset($q['answers'][4])) {
echo $q['answers'][4];
}
?></td>
<td><?php
if (isset($q['correctAnswer'])) {
echo $q['correctAnswer'];
}
?></td>
<td><a href="">Edit</a> / <a href="" ng-click="delete()">Delete</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</form>
</div>
我已经阅读了一些教程,但不太清楚。
答案 0 :(得分:0)
首先,您需要一些后端代码来实际删除该行。您还需要使用angular来创建表(example)。假设已经到位,您可以执行以下操作:
angular.module('app', []).controller('questionEditCtrl', ['$scope', '$timeout', '$http', 'DataService', function ($scope, $timeout, $http, DataService) {
$scope.delete = function () {
console.log("submit pressed");
$http.delete("/api/deleteRow", id).then(
function(results){
// You can either remove the row from the array using splice:
$scope.quizes.splice(id, 1;
// Or simply call refresh
$scope.refresh();
});
}
}]);
上述代码尚未实现,但应该概述如何完成。
答案 1 :(得分:0)
您需要让角度管理测验列表,并让角度渲染列表。
SELECT Name.ID AS Expr2, Name.MEMBER_TYPE, Name.STATUS, Name.COMPANY, Demo_Chapter.CH_UNIVERSITY, CONVERT(VARCHAR(10),
Demo_Chapter.CH_INSTALLED_DATE, 101) AS ChInstlDate, CONVERT(VARCHAR(10), Demo_Chapter.CH_INACTIVE_DATE, 101) AS ChInctvDate,
CONVERT(VARCHAR(10), Demo_Chapter.CH_SEC_INACTIVE_DATE, 101) AS ChSecDate, CONVERT(VARCHAR(10), Demo_Chapter.CH_REINSTALLED_DATE, 101)
AS ChReInstall, CONVERT(VARCHAR(10), Demo_Chapter.CH_THIRD_INSTALL, 101) AS ThrdInstall, CONVERT(VARCHAR(10), Demo_Chapter.CH_FOURTH_INSTALL,
101) AS FrthInstall, CONVERT(VARCHAR(10), Demo_Chapter.CH_TH_INACTIVE_DATE, 101) AS ThInctvDate, Demo_Chapter.CH_TH_INACTIVE_REASON,
CONVERT(VARCHAR(10), Demo_Chapter.CH_FR_INACTIVE_DATE, 101) AS FrInctvDate, Demo_Chapter.CH_FR_INACTIVE_REASON,
Demo_Chapter.CH_CARNEGIE_BASIC, Demo_Chapter.CH_CARNEGIE_SS, Demo_Chapter.CH_CARNEGIE_UNDER, Demo_Chapter.CH_CARNEGIE_ENROLL,
Demo_Chapter.CH_ATHL_CONF, Demo_Chapter.CH_UG_ENROLL, Demo_Chapter.CH_NUM_WMN_STUD, Demo_Chapter.CH_SEC_INACTIVE_REASON,
Demo_Chapter.CH_INACTIVE_REASON, Demo_Chapter.CH_RECRUIT_TIME, Demo_Chapter.CH_TERMS, Demo_Academic.AA_CHAPTER_GPA,
Demo_Academic.AA_TERM, Demo_Academic.AA_YEAR, CONVERT(VARCHAR(10), Demo_Chapter_Events.CE_EVENT_DATE, 101) AS EvntDate,
Demo_Chapter_Events.CE_EVENT_TYPE
FROM Name INNER JOIN
Demo_Chapter ON Name.ID = Demo_Chapter.ID INNER JOIN
Demo_Chapter_Events ON Name.ID = Demo_Chapter_Events.ID LEFT OUTER JOIN
Demo_Academic ON Name.ID = Demo_Academic.ID
WHERE (Name.MEMBER_TYPE = 'CCHP') AND (Name.STATUS IN ('A', 'SUSP')) AND (Demo_Academic.AA_TERM = 'SPRING') AND (Demo_Academic.AA_YEAR = '1415') AND
(Demo_Chapter_Events.CE_EVENT_DATE BETWEEN CONVERT(DATETIME, '2015-08-01 00:00:00', 102) AND CONVERT(DATETIME, '2015-12-31 00:00:00', 102)) AND (Demo_Chapter_Events.CE_EVENT_TYPE = 'SOCIAL')
(function() {
'use strict';
angular.module('app', []).controller('questionEditCtrl', ['$scope', '$timeout', '$http',
function($scope, $timeout, $http) {
var url = 'myurl';
//get the quzes from service via $http.get
$scope.quizes = [{
question_id: 1,
quesiton: "foo?"
}, {
question_id: 2,
quesiton: "bar?"
}];
$scope.delete = function(quiz) {
console.log("submit pressed");
$http.delete(url, {
id: quiz.question_id
}).then(function() {
//server delete was successful
_.remove($scope.quizes, quiz); //using lodash
}
}
}]);
})();