<div class="table-responsive">
<table class="jh-table table table-striped">
<thead>
<tr jh-sort="vm.predicate" ascending="vm.reverse" callback="vm.reset()">
<!-- <th jh-sort-by="id"><span>ID</span> <span class="glyphicon glyphicon-sort"></span></th> -->
<th><input type="checkbox" ng-change="vm.selectAll()" ng-model="vm.checkAll[vm.page]"></th>
<th jh-sort-by="bookName"><span>Book Name</span> <span class="glyphicon glyphicon-sort"></span></th>
<th jh-sort-by="remarks"><span>Remarks</span></th>
<th></th>
</tr>
</thead>
<tbody infinite-scroll="vm.loadPage(vm.page + 1)" infinite-scroll-disabled="vm.page >= vm.links['last']">
<tr ng-repeat="book in vm.books track by book.id">
<!-- <td><a ui-sref="book-detail({id:book.id})">{{book.id}}</a></td> -->
<td><input type="checkbox" ng-model="vm.checkboxes[book.id]" ng-change="vm.select(book)"/></td>
<!--<td><input type="checkbox" ng-model="seletedTasks[$index]"/></td> -->
<td>{{($index + 1) + (vm.page - 1) * vm.itemsPerPage}}</td>
<td>{{book.bookName}}</td>
<td>{{book.remarks}}</td>
<td class="text-right">
<div class="btn-group flex-btn-group-container">
<button type="submit"
ui-sref="book-detail({id:book.id})"
class="btn btn-info btn-sm">View
<span class="glyphicon glyphicon-eye-open"></span>
<span class="hidden-xs hidden-sm"></span>
</button>
<button type="submit"
ui-sref="book.edit({id:book.id})"
class="btn btn-primary btn-sm">Edit
<span class="glyphicon glyphicon-pencil"></span>
<span class="hidden-xs hidden-sm"></span>
</button>
<button type="submit"
ui-sref="book.delete({id:book.id})"
class="btn btn-danger btn-sm">Delete
<span class="glyphicon glyphicon-remove-circle"></span>
<span class="hidden-xs hidden-sm"></span>
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="form-group">
<button ng-if="0 < vm.selectedItems.length" type="submit"
tooltip-placement="bottom" uib-tooltip="{{'entity.action.delete' | translate}}"
ui-sref="pen.delete-sel({selectedItems: vm.selectedItems})"
class="btn btn-danger btnn xs">Delete
<i class="fa fa-trash-o"></i>
</button>
</div>
(function() {
'use strict';
angular
.module('penApp')
.controller('BookController', BookController);
BookController.$inject = ['$scope', '$state', 'Book', 'ParseLinks', 'AlertService'];
function BookController ($scope, $state, Book, ParseLinks, AlertService) {
var vm = this;
vm.books = [];
vm.loadPage = loadPage;
vm.page = 0;
vm.links = {
last: 0
};
vm.predicate = 'id';
vm.reset = reset;
vm.reverse = true;
vm.checkAll = [];
var map = {};
vm.checkboxes = [];
vm.selectedItems = [];
vm.selectAll = selectAll;
vm.select = select;
function selectAll () {
var value = vm.checkAll[vm.page];
angular.forEach(vm.books, function(item) {
if (angular.isDefined(item.id)) {
if(vm.checkboxes[item.id] != value) {
vm.checkboxes[item.id] = value;
vm.select(item);
}
}
});
};
function select (item) {
var value = vm.checkboxes[item.id];
if(value) {
vm.selectedItems.push(item);
if(map[vm.page] == null) map[vm.page] = 1;
else map[vm.page] = map[vm.page] + 1;
if(map[vm.page] == vm.books.length) {
vm.checkAll[vm.page] = true;
}
} else {
vm.selectedItems.splice(item, 1);
if(map[vm.page] == null) map[vm.page] = 0;
else map[vm.page] = map[vm.page] - 1;
if(map[vm.page] < vm.books.length) {
vm.checkAll[vm.page] = false;
}
}
};
loadAll();
function loadAll () {
Book.query({
page: vm.page,
size: 20,
sort: sort()
}, onSuccess, onError);
function sort() {
var result = [vm.predicate + ',' + (vm.reverse ? 'asc' : 'desc')];
if (vm.predicate !== 'id') {
result.push('id');
}
return result;
}
function onSuccess(data, headers) {
vm.links = ParseLinks.parse(headers('link'));
vm.totalItems = headers('X-Total-Count');
for (var i = 0; i < data.length; i++) {
vm.books.push(data[i]);
}
}
function onError(error) {
AlertService.error(error.data.message);
}
}
function reset () {
vm.page = 0;
vm.books = [];
loadAll();
}
function loadPage(page) {
vm.page = page;
loadAll();
}
}})();
.state('books.delete-sel', {
parent: 'books',
url: '/delete',
data: {
authorities: ['ROLE_USER']
},
params: {
selectedItems: null
},
onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) {
$uibModal.open({
templateUrl: 'app/entities/book/book-delete-sel-dialog.html',
controller: 'BookDeleteController',
controllerAs: 'vm',
size: 'md'
}).result.then(function() {
$state.go('books', null, { reload: true });
}, function() {
$state.go('^');
});
}]
});
(function() {
'use strict';
angular
.module('penApp')
.factory('Book', Book);
Book.$inject = ['$resource', 'DateUtils'];
function Book ($resource, DateUtils) {
var resourceUrl = 'api/books/:id';
return $resource(resourceUrl, {}, {
'query': { method: 'GET', isArray: true},
'deleteSel': { method: 'POST', isArray: true, params:{'delete-sel':''}},
'get': {
method: 'GET',
transformResponse: function (data) {
if (data) {
data = angular.fromJson(data);
}
return data;
}
},
'update': { method:'PUT' }
});
}})();
(function() {
'use strict';
angular
.module('schoolApp')
.controller('BookDeleteController',BookDeleteController);
BookDeleteController.$inject = ['$uibModalInstance', '$stateParams', 'Book'];
function BookDeleteController($uibModalInstance, $stateParams, Book) {
var vm = this;
vm.selectedItems = $stateParams.selectedItems;
vm.clear = clear;
vm.confirmDelete = confirmDelete;
function clear () {
$uibModalInstance.dismiss('cancel');
}
function confirmDelete (id) {
Book.deleteSel({}, vm.selectedItems,
function () {
$uibModalInstance.close(true);
},
function () {
console.log("An error occurred");
});
}
}})();
@RequestMapping(value = "/books",
params = "delete-sel",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<Void> deleteBooks(@RequestBody List<Book> books) {
log.debug("REST request to delete Books : {}", books.size());
bookRepository.delete(books);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert("book", null)).build();
}
当我取消注释按钮代码(books.html)时。我在桌子上看不到任何记录。如果我评论那个按钮,那么我可以看到记录。我想删除由复选框选中的记录。我不知道该怎么做。我认为uib-tooltip存在问题。有人可以帮帮我吗?我应该在代码中更改什么?
答案 0 :(得分:2)
更新&#39;&#39; books.delete-sel&#39;在#book; state.js&#39;对此:
.state('book.delete-sel', { // Previous: 'books.delete-sel'
parent: 'book',
url: '/delete-sel', // Previous: '/delete'
data: {
authorities: ['ROLE_USER']
},
params: {
selectedItems: null
},
onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) {
$uibModal.open({
templateUrl: 'app/entities/book/book-delete-sel-dialog.html', // The book-delete-sel-dialog.html didn't exist before
/*controller: 'BookDeleteController',*/
controller: 'BookDeleteSelController',
controllerAs: 'vm',
size: 'md'
}).result.then(function() {
$state.go('book', null, { reload: true }); // Previous: 'books'
}, function() {
$state.go('^');
});
}]
})
有关完整的源代码,请参阅此link。
答案 1 :(得分:0)
似乎翻译过滤器无法正常工作,这反过来会中止您的控制器,因此无法通过角度编译书籍和/或html的加载,因此不会执行ng-repeat。
您是否在工具提示中尝试了简单的文字
uib-tooltip="Delete"
?如果这样做,您可以尝试使用$translate
:
//...
BookController.$inject = ['$scope', '$state', 'Book', 'ParseLinks', 'AlertService', '$translate'];
BookController ($scope, $state, Book, ParseLinks, AlertService, $translate) {
//...
vm.deleteTooltip = $translate.instant('entity.action.delete');
//...
然后
uib-tooltip="{{vm.deleteTooltip}}"