template读取数据json

来源:互联网 发布:红蜘蛛软件安装 编辑:程序博客网 时间:2024/06/08 11:17


<!DOCTYPE html>

<html>


<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title>中医体质</title>
<link rel="stylesheet" href="resources/css/public.css" />
<link rel="stylesheet" href="resources/css/health_ques.css" />
</head>


<body>
<header class="bar_nav">
<a class="step" href="javascript:">下一步 1/6</a>
<h2 class="title">健康问卷</h2>
</header>
<section class="pad_top62">
<form id="china">
<section class="h_total" id="questionShower">
<h3>中医体质</h3>
<!--<div class="form_group">
<label class="cell2_title">饮食偏向</label>
<ul class="cell3_choose">
<li>
<input type="radio" name="dietBlance" id="diet01" value="2" class="radio">
<label class="radio" for="diet01">荤素均衡</label>
</li>
<li>
<input type="radio" name="dietBlance" id="diet02" value="2" class="radio">
<label class="radio" for="diet02">荤食为主</label>
</li>
<li>
<input type="radio" name="dietBlance" id="diet03" value="2" class="radio">
<label class="radio" for="diet03">素食为主</label>
</li>
</ul>
</div>-->
</section>
</form>
</section>
<script type="text/javascript" src="resources/js/jquery-2.1.1.min.js" ></script>
<script type="text/javascript" src="resources/js/health_ques.js"></script>
<script type="text/javascript" src="resources/js/template.js"></script>
<script type="text/javascript">
$(function() {
chinaLoad();
});


function chinaLoad() {
var url = "resources/data/chiandatea.json";
$.get(url, function(data) {
if(data) {
console.log(data);
$("#questionShower").append(template("liTpl", data))
}
}, "json");
}
</script>
<script type="text/html" id="liTpl">
{{each arr as firstarr}}
{{each firstarr.questions as secondarr}}
{{if !secondarr.dispaly}}
   <div class="form_group">
<label class="cell2_title">{{secondarr.question}}</label>
<ul class="cell3_choose">
{{each secondarr.answers as thindarr thirdindex }}
<li>
<input type="radio" name="{{secondarr.code}}" id="{{secondarr.code+thirdindex+1}}" value="{{thindarr.value}}" class="radio">
<label class="radio" for="{{secondarr.code+thirdindex+1}}">{{thindarr.name}}</label>
</li>
{{/each}}
</ul>
</div>
{{/if}}
{{/each}}
{{/each}}
</script>
</body>


</html>