var solution_case_pagesize = 6; $(function(){ loadsolu(solution_case_pagesize, 1); }); /** * 加载典型方案 * @param currentpage * @return */ function loadsolu(pagesize, currentpage){ $.ajax({ type: "post", url: root_path + "/solution/list", data: "pagesize=" + pagesize + "¤tpage=" + currentpage, datatype: "json", success: function(resultmap){ $("#solution_list").empty(); if(resultmap!=null && resultmap.dictpage!=null){ var dictpage = resultmap.dictpage; var dictlist = dictpage.content; var solutionlist = resultmap.solutionlist; addsolu(dictlist, solutionlist); //设置分页 var pageopt = { totalpages : dictpage.totalpages ,currentpage : dictpage.number , numberofpages : 10 }; setpaginator( pageopt ); } }, error: function(){ alert(" list error!"); } }); } //设置分页条 function setpaginator( pageopt ){ //var options = pageopt; var options = { alignment:'center', onpageclicked: function(e,originalevent,type,page){ loadsolu( solution_case_pagesize ,page ); } }; options = jquery.extend(pageopt, options); $('#pager').bootstrappaginator(options); } /** * 新增典型方案div * @param dictlist * @param solutionlist * @return */ function addsolu(dictlist, solutionlist){ if(dictlist!=null){ var solhtml = ""; for(var outindex=0; outindex < dictlist.length; outindex++){ var dict = dictlist[outindex]; if(outindex % 2 == 0){ solhtml += '
'; }else{ solhtml += '
'; } solhtml += '
'; //不同颜色 if(outindex == 0){ solhtml += '
'; }else if(outindex == 1){ solhtml += '
'; }else if(outindex == 2){ solhtml += '
'; }else if(outindex == 3){ solhtml += '
'; }else if(outindex == 4){ solhtml += '
'; }else{ solhtml += '
'; } solhtml += '
'; solhtml += '

' + dict.name + '

'; solhtml += '

'; solhtml += subnewstr(dict.remark, 92); solhtml += '

'; solhtml += '
'; solhtml += '
'; solhtml += '
'; solhtml += '
    '; solhtml += addsoluul(solutionlist, dict); solhtml += '
'; if(dict.solucount > 3){ //solhtml += 'more+'; solhtml += 'more' + '+'; } solhtml += '
'; solhtml += '
'; //solhtml += ''; if(dict.piclink==null || dict.piclink == ""){ solhtml += ''; }else{ solhtml += ''; } solhtml += '
'; solhtml += '
'; solhtml += '
'; } $("#solution_list").append(solhtml); } } /** * 新增典型方案ul * @param solutionlist * @param dict * @return */ function addsoluul(solutionlist, dict){ var solhtml = ""; if(solutionlist!=null){ for(var inindex=0; inindex < solutionlist.length; inindex++){ var solution = solutionlist[inindex]; if(dict.value == solution.type){ solhtml += '
  • ' + solution.title + '
  • '; } } } return solhtml; } /** * 截取字符串 * js的length方法计算的是个数,一个汉字长度是1,一个字母长度也是1。本方法里面,定义:一个汉字长度为2,相当于2个字母的长度 */ function subnewstr(str, max){ if(str==null || str==""){ return ""; } var char_length = 0; var new_str = ""; for (var i = 0; i < str.length; i++){ var son_char = str.charat(i); //如果是汉字(包括¥等特殊字符),长度大于2,其他任何字符,长度均为1另外:根据需求规则,限制n个字,一个字=2个字符 encodeuri(son_char).length > 2 ? char_length += 2 : char_length += 1; if(char_length <= max){ new_str += son_char; } } if(char_length > max){ new_str += "..."; } return new_str; }