<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
 <%@include file="/views/common.jsp"%>
</head>
<style>
</style>
<body>
<div>
	<textarea id="errorData" name="errorData" style="display:none"></textarea>
	<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="refreshData()">没有错题？点击我试试</button>
	<!--用了layui的tpl模板引擎-->
    <div id="view"></div>
</div>
</body>
<script id="errorInfo" type="text/html">
    <div class="layui-row">
        <form class="layui-form">
			  <ul>
                <li class="layui-form-item" style=" text-align: left;margin-left: 20px">
					<!--对后台传过来的json数据进行遍历-->
					{{# for (var i = 0; i < d.length; i++) {  }}
						</br>
      					<span>{{d[i]}}</span>
                	{{# } }}	
                </li>
            </ul>
        </form>
    </div>
</script>
<script>
	function refreshData(){
		var errorData = $("#errorData").val().split("-,")
		errorDataHandle(errorData)
	}
	// 父页面调用此方法，再调用layui.use里的方法，把数据传进去，再通过tpl渲染到页面
 	/* function initErrorDataHandle(errorData){
		errorDataHandle(errorData)
	} */
	layui.use(['form', 'laytpl', 'layer'], function(){ //独立版的layer无需执行这一句
		var  $    = layui.jquery, 
	       form   = layui.form, 
	       layer  = layui.layer, 
	       laytpl = layui.laytpl;
		form.render();
		// layui.use里的方法要供外部调用，需要加上window
		window.errorDataHandle = function(errorData){
			var getTpl = document.getElementById('errorInfo').innerHTML,
		          view = document.getElementById('view');
			laytpl(getTpl).render(errorData, function (html) {
				view.innerHTML = html;
			});
			form.render();
		}
	});
</script>

</html>