1:全选和反选
全选:
<input type="checkbox" id="selectAll">
列表:
<input type="checkbox" name="ids" value="‘+data.openid+‘" >‘
js效果:
//全选、反选
$(function() {
$("#selectAll").click(function() {
$("input[name=‘ids‘]").prop("checked", this.checked);
});
$("input[name=‘ids‘]").click(function() {
var $ids = $("input[name=‘ids‘]");
$("#selectAll").prop("checked",$ids.length ==$ids.filter(":checked").length ? true :false);
});
});
function _bindCheckboxClick(){
$("input[name=‘ids‘]").click(function() {
var $ids = $("input[name=‘ids‘]");
$("#selectAll").prop("checked",$ids.length ==$ids.filter(":checked").length ? true :false);
});
}
修改:
function batchMove(){
//获取最新分组id
var wxGroupId = $("#groupBathList").val();
//获取选择的粉丝集合
var openidArr = new Array;
$("input[type=checkbox][name=ids]:checked").each(function(i){
openidArr[i] = $(this).val();
});
//转换为逗号隔开的字符串
var openids = openidArr.join(‘,‘);
//提交动作
var url = "<%=basePath%>";
url = url + "fan/op/batchUpdateFan.shtml";
var params = {};
params.openids = openids;
params.wxGroupId = wxGroupId;
$.post(url, params,
function (data) {
if (data.success == 1) {
$(‘#errmsg‘).calert(‘alert‘,"修改成功!");
query();
}
},"json");
}
后台处理:
public String batchUpdateFan(){
try {
map = new HashMap<String, Object>();
map.put("success", 1);
// 需要同步的公众号id
WxAccount wxAccount_session = getSessUser().getWxAccount_session();
String access_token =WxConstant.getRealAccessToken(wxAccount_session.getAccountappid());
if(StringUtils.isNotNull(openids)){
List<String> openidList = StringUtils.stringToListStr(openids, ",");
if(openidList != null && openidList.size() >0){
for(String openid :openidList){
Fan fan = new Fan();
fan.setOpenid(openid);
fan = fanService.getFan(fan);
if(fan!= null){
fan.setWxGroupId(Integer.parseInt(wxGroupId));
fanService.updateFan(fan);
}
}
}
// 同步用户分组
String batchMoveUserToGroupUrl = WxConstant.getBatchMoveUserToGroupUrl(access_token);
JSONObject jsonObject = new JSONObject();
jsonObject.put("openid_list", openidList);
HttpUtils.post(batchMoveUserToGroupUrl, g.toJson(jsonObject));
}
} catch (Exception e) {
e.printStackTrace();
map.put("success", 0);
map.put("errMsg", e.getMessage());
}
return "toResult";
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-15 16:08:58