一,通过ajax向后台传递批量对象参数
前端:
var selectType = [];
var point = {
tableName: 'T_CSBJXXB',
type: bjbm,
dataArea: dataAreaCode
}
selectType.push(point);
//多个对象就向selectType 数组内推入多个point对象
$.ajax({
type : "POST",
dataType : 'json',
url : "/PowerOfManagement/getpointByAreacode",
//将批量对象selectType数组转成字符串,后台以string类型接收
data : {'str':JSON.stringify(selectType),'pageSize':0,'pageNum':0},
success : function(data) {
if (data.success) {
}
},
error : function() {
console.log("请求出错,请联系管理员!");
}
});
后台:
注意JSON对象属于com.alibaba.fastjson 包
前段转换的str的格式是
"[{"tableName":"T_BMLLXXB","type":"0|1|2","dataArea":"320505"},{"tableName":"T_JKXXB","type":"0|1|2","dataArea":"320505"}]"
@RequestMapping(value = "getpointByAreacode", method = RequestMethod.POST)
public void getpointByAreacode(HttpServletRequest request, HttpServletResponse response, String str,int pageSize,int pageNum){
Result result = new Result();
try {
// fastjson将字符串转换成对象集合
List<PointOfManagementPower> list =
JSON.parseArray(selectType,PointOfManagementPower.class);
result.setMessage("查询成功");
result.setSuccess(true);
result.setList(list );
}catch (Exception e){
result.setSuccess(false);
result.setMessage("获取失败!"+e);
}
this.print(result.toString(),response);
}
二,jq查找语句
//area-code是页面上一直有的,不要动态拼接的元素
//查找area-code下的 button标签内的 role属性以town开头的 a标签的value值
// find查找不只子类,孙子类,重孙子类等等向下都内查到
$("#area-code").find("button a[role^='town']").attr("value");
//向上一级一级查找到class为btn-parent-div的父元素,然后再找内部checkbox的标签集合,并遍历
//checkbox在我这里是动态拼接内的标签,判断选中不能用直接attr('check')判断,要用is函数
//修改属性要用prop方法
$(this).parent().parent().parent().parent().parent().parent(".btn-parent-div").find("input[type='checkbox']").each(function () {
//这里的this对象是遍历的每一个input[type='checkbox']对象,而不是开头的this对象
if ($(this).is(":checked")) {
$(this).prop("checked", false);
}
})
//选中
$(this).prop("checked", true);
$(this).parent().parent().parent().parent().parent().addClass("btn-primary");
$(this).parent().parent().parent().parent().parent().removeClass("btn-warning");
三 、jq中的事件
//鼠标滚轮滚动事件 据说兼容性很高
$("#mapDiv").on("mousewheel DOMMouseScroll",function (e) {
// console.log("666");
//判断滚动方向
//chrome & ie || Firefox 区分浏览器
var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ?1 :-1))
|| (e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1));//Firefox
if (delta > 0) {
// 向上滚
console.log("wheelup");
} else if (delta < 0) {
// 向下滚
console.log("wheeldown");
}
});
//绑定点击事件
//input[type='checkbox']是我动态拼接到内部的 .select-type-list-city-sec固定存在
$(".select-type-list-city-sec").on("click","input[type='checkbox']",function (e) {
//这里的this对象是点击的input[type='checkbox'],而不是.select-type-list-city-sec
$(this).parent();
})
//点击事件li a标签也是动态拼接到area-code内部的
$("#area-code").on("click","li a[role^='town']",function () {
//获取a标签的value属性 this对象是a标签
var code = $(this).attr("value");
})