这里举得例子是:JS直接从后台Contorller中(SpringMVC中的model中)获得数值的值

Contorller 此处将 talentIntegralRecordsDay talentIntegralRecordsIntegral 两个数组用JSON.toJSONString()封装。

    @SuppressWarnings("deprecation")
@RequestMapping("/integralParadise")
public ModelAndView Welcome(HttpServletRequest request){ Users user = userService.currentUser(request);
user.getTalentUser().getIntegral();
System.out.println(user.getTime().getDate()); TalentIntegralRecord[] signInTalentIntegralRecords= wechatIntegralService.getUserSignInTalentIntegralRecords(user.getId());
int size = signInTalentIntegralRecords.length;
int[] talentIntegralRecordsDay = new int[size];
Long[] talentIntegralRecordsIntegral = new Long[size];
for(int i=0;i<signInTalentIntegralRecords.length;i++){
talentIntegralRecordsDay[i]=signInTalentIntegralRecords[i].getOperatorTime().getDate();
talentIntegralRecordsIntegral[i]=signInTalentIntegralRecords[i].getIntegral();
}
Map<String,Object> map = new HashMap<String,Object>();
map.put("talentIntegralRecordsDay", JSON.toJSONString(talentIntegralRecordsDay));
map.put("talentIntegralRecordsIntegral", JSON.toJSONString(talentIntegralRecordsIntegral));
return new ModelAndView("wechat/integralParadise/rili",map);
}

前台JSP 因为用到两个数组数据的JS代码为页面引用的JS代码所以要在页面中先声明获得后台两个数组(这段JS代码应在引用的JS文件前面)

<script type="text/javascript">
$(document).ready(function(){
window.talentIntegralRecordsDay = ${talentIntegralRecordsDay};
window.talentIntegralRecordsIntegral = ${talentIntegralRecordsIntegral};
});
</script>

引用的JS文件 开始就获得了两个数组的值

$(function() {
var signFun = function() { var dateArray = window.talentIntegralRecordsDay;// 假设已经签到的
var talentIntegralRecordsIntegral = window.talentIntegralRecordsIntegral;
var $dateBox = $("#js-qiandao-list"),
$currentDate = $(".current-date"),
$qiandaoBnt = $("#js-just-qiandao"),
_html = '',
_handle = true,
myDate = new Date();
$currentDate.text(myDate.getFullYear() + '年' + parseInt(myDate.getMonth() + 1) + '月' + myDate.getDate() + '日'); var monthFirst = new Date(myDate.getFullYear(), parseInt(myDate.getMonth()), 1).getDay(); var d = new Date(myDate.getFullYear(), parseInt(myDate.getMonth() + 1), 0);
var totalDay = d.getDate(); //获取当前月的天数 for (var i = 0; i < 42; i++) {
_html += ' <li><div class="qiandao-icon"></div></li>'
}
$dateBox.html(_html) //生成日历网格 var $dateLi = $dateBox.find("li");
for (var i = 0; i < totalDay; i++) {
$dateLi.eq(i + monthFirst).addClass("date" + parseInt(i + 1));
for (var j = 0; j < dateArray.length; j++) {
if (i == dateArray[j]) {
$dateLi.eq(i).addClass("qiandao");
var integral;
if(talentIntegralRecordsIntegral[j]==0){
integral="大转盘";
}else{
integral="+"+talentIntegralRecordsIntegral[j];
}
$dateLi.eq(i).find("div").text(integral);
}
}
} //生成当月的日历且含已签到 $(".date" + myDate.getDate()).addClass('able-qiandao'); $dateBox.on("click", "li", function() {
if ($(this).hasClass('able-qiandao') && _handle) {
$(this).addClass('qiandao');
qiandaoFun();
}
}) //签到 $qiandaoBnt.on("click", function() {
if (_handle) {
qiandaoFun();
}
}); //签到 function qiandaoFun() {
$qiandaoBnt.addClass('actived');
openLayer("qiandao-active", qianDao);
_handle = false;
} function qianDao() {
$(".date" + myDate.getDate()).addClass('qiandao');
}
}(); function openLayer(a, Fun) {
$('.' + a).fadeIn(Fun)
} //打开弹窗 var closeLayer = function() {
$("body").on("click", ".close-qiandao-layer", function() {
$(this).parents(".qiandao-layer").fadeOut()
})
}() //关闭弹窗 $("#js-qiandao-history").on("click", function() {
openLayer("qiandao-history-layer", myFun); function myFun() {
console.log(1)
} //打开弹窗返回函数
}) })

JS中直接从java后台获得对象的值(数组的值)的更多相关文章

  1. python中的is判断引用的对象是否一致,==判断值是否相等

    python中的is判断引用的对象是否一致,==判断值是否相等 a = 10 b = 20 list = [1,2,3,4,5] print(a in list) print(b not in lis ...

  2. 如何向java后台的对象中传数组

    1.后台对象的参数需要是是list对象 /* * copyright : GLOBALROAM Ptd Ltd * VmCreateInfo.java * Author: * zhangpengyan ...

  3. HTML5+js页面传值给Java后台的小技巧

    页面传值小技巧 平常我们在做的web项目,一般一个HTML页面上会有好几个步骤,step_num①,step_num②,step_num③,一般先显示step_num①,根据跳转条件显示step_nu ...

  4. js前台加密,java后台解密实现

    参考资料: JS前台加密,java后台解密实现

  5. JS中把字符串转成JSON对象的方法

    在JS中,把 json 格式的字符串转成JSON对象,关键代码 json = eval('('+str+')'); <!DOCTYPE html PUBLIC "-//W3C//DTD ...

  6. Js中把JSON字符串转换为JSON对象(eval()、new Function())

    在JS中将JSON的字符串解析成JSON数据格式,一般有两种方式: 1.一种为使用eval()函数. 2. 使用Function对象来进行返回解析. 第一种解析方式:使用eval函数来解析,并且使用j ...

  7. JS中一些常用的内置对象

    在JS中,经常会遇到明明知道一个对象有某个属性或方法,可是又不知道怎么写的情况.下面,我就罗列了一些JS中常用的内置对象的属性和方法. Math对象: Math对象的作用是执行常见的算术任务. 首先M ...

  8. js中的事件,内置对象,正则表达式

    [JS中的事件分类] 1.鼠标事件: click/dbclick/mouseover/mouseout/mousemove/mousedown/mouseup 2.键盘事件: keydown: 键盘按 ...

  9. JS基础--函数与BOM、DOM操作、JS中的事件以及内置对象

       前   言 絮叨絮叨 这里是JS基础知识集中讲解的第三篇,也是最后一篇,三篇JS的基础,大多是知识的罗列,并没有涉及更难得东西,干货满满!看完这一篇后,相信许多正在像我一样正处于初级阶段的同学, ...

随机推荐

  1. JavaScript Array对象sort() 方法小结

    sort() 方法用于对数组的元素进行排序. 语法arrayObject.sort(sortfunction) 参数sortfunction 可选.规定排序顺序.必须是函数. 返回值对数组的引用.请注 ...

  2. WebPack 简明学习教程

    WebPack 简明学习教程 字数1291 阅读22812 评论11 喜欢35 WebPack是什么 一个打包工具 一个模块加载工具 各种资源都可以当成模块来处理 网站 http://webpack. ...

  3. AWS-CDH5.5安装 CM配置节点

    在CM节点上进行安装时出现错误: ================================================================================ Pa ...

  4. CentOS 6.6编译安装Nginx1.6.2+MySQL5.6.21+PHP5.6.3

    http://www.osyunwei.com/archives/8867.html 一.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables #编辑防火墙配置 ...

  5. ubuntu方块乱码

    更改下环境变量/etc/default/locale LANG="en_US.UTF-8"LANGUAGE="en_US:en"

  6. Informatica - Powercenter 英文版资料(转载)

    Informatica - Powercenter 英文版资料 http://gerardnico.com/wiki/powercenter/powercenter

  7. 006-Map、Tuple、Zip实战解析

    006-Map.Tuple.Zip实战解析 实战代码 Map实战 本身是映射,映射关系在实际中应用非常广泛,比如:配置信息都是Key-Value形式 键值对不存在下边关系 是一个immutable(不 ...

  8. json字符串返回到js中乱码

    Ajax 的post请求值返回到js中时出现中文乱码的情况,但是在action中写入时并未乱码,解决办法在action中写入前,加上这两行: request.setCharacterEncoding( ...

  9. Hibernate入门与简谈

    Hibernate jdbc Java Databases Connectivity, 他是提供了一组Java API来访问关系数据库的Java程序.这些Java API 可以使Java应用程序执行S ...

  10. 【python】属性

    在python中,一切皆是对象(object),对象拥有很多属性(arrtribute) 属性分2种 类属性(class attribute):类自身定义or继承 对象属性(object attrib ...