前端之家收集整理的这篇文章主要介绍了
angular js 全选/消除全选 和 layer删除确认框,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
js:
// 全选/取消全选
$scope.selectAll = function(object) {
for (var i = 0; i < $scope.listLiveRoom.length; i++) {
$scope.listLiveRoom[i].ISCHECK = !$scope.selAll;
}
};
// checkBox状态改变
$scope.chkChange = function() {
var j = 0;
for (var i = 0; i < $scope.listLiveRoom.length; i++) {
if (!$scope.listLiveRoom[i].ISCHECK) {
$scope.selAll = false;
}
if ($scope.listLiveRoom[i].ISCHECK) {
j++;
}
}
if (j == $scope.listLiveRoom.length) {
$scope.selAll = true;
}
};
// 删除确认对话框表示
$scope.showConfirm = function() {//TODO
// 选中对象确认
var intCount = 0;
for (var i = 0; i < $scope.listBackPlayRoom.length; i++) {
if ($scope.listBackPlayRoom[i].ISCHECK2 == true) {
intCount++;
}
}
if (intCount == 0) {
$scope.error = "请选择删除对象。";
return;
}
var title = "确认";
$scope.confirmContent = '确定要删除吗?';
var mydom = $('#confirmDlg');
layer.open({
type : 1,shadeClose : false,area : [ '450px','160px' ],title : title,content : mydom,btn : [ '确定','取消' ],btn1 : function(index,layero) {
},btn2 : function(index) {
layer.close(index);
},yes : function(index,layero) {
layer.close(index);
delObj();
},success : function(layero,index) {
mydom.show();
},end : function() {
mydom.hide();
},});
};
function delObj() {
$scope.error = "";
var idList = "";
// 获取要删除的数据
if ($scope.listBackPlayRoom&& $scope.listBackPlayRoom.length > 0) {
for (var i = 0; i < $scope.listBackPlayRoom.length; i++) {
if ($scope.listBackPlayRoom[i].ISCHECK2 == true) {
if (idList != "") {
idList += ",";// 以逗号分隔
}
idList += $scope.listBackPlayRoom[i].playbackId;
}
}
}
if (idList != "") {
$http({
method : "post",url : "find/deleteBackPlayRoom",data : {
"idList" : idList
}
}).success(function(rs,status,headers,config) {
chkSession(rs);
if (rs.status == 0) {
// 更新后数据表示
$scope.inittable();
select();
$scope.success = rs.message;
} else {
$scope.error = "操作失败。";
}
}).error(function(rs,config) {
$scope.error = "操作时,发生系统异常。";
});
}
};
Freemarker:
<th><input id="all2" name="check2" type="checkBox" data-ng-model="selAll2" data-ng-click="selectAll2(this)">
</th>
<td><input id="special2" type="checkBox" data-ng-model="row.ISCHECK2" data-ng-change="chkChange2()"></td>
<div id="dialog">
<div id="confirmDlg" style="display: none;">
<div style="margin: 20px;">
<label id="confirmContent"> {{confirmContent}}</label>
</div>
</div>
</div>
Controller:
// TODO 删除playbackRoom
public void deleteBackPlayRoom() throws ServiceException {
Map<String,Object> result = new HashMap<>();
UserBean userBean = getSessionAttr(CommonValue.USER_SESSION_KEY);
String playbackRoomIds = getPara("idList");
String[] idArrList = playbackRoomIds.split(",");
String updUserId = "maple";
Timestamp ts = new Timestamp(System.currentTimeMillis());
if (userBean != null) {
updUserId = userBean.getUpdUsrId();
// updDat = userBean.getUpdDat();
}
int total = 0;
int success = 0;
if (idArrList != null && idArrList.length > 0) {
for (int i = 0; i < idArrList.length; i++) {
total++;
String id = idArrList[i];
if (!StringUtils.isEmpty(id)) {
// 删除
TblplaybackroomBo updObj = null;
updObj = playbackDao.selectByIdForUpdate(id);
updObj.delFlg = 1;
updObj.updDat = ts;
updObj.updUsrId = updUserId;
playbackDao.update(updObj);
success++;
} else {
result.put("status",-1);
}
}
result.put("status",0);
result.put("message","删除处理结束。成功:" + success + "条,失败:" + (total - success) + "条。");
}