0
您好我想提出HTTP GET調用返回JSON如下MVC控制器動作:車把不正確填充模板JSON響應
[
{
"PlanCode": "P001 ",
"PlanName": "Plan1 "
},
{
"PlanCode": "P002$ ",
"PlanName": "Plan2$ "
},
{
"PlanCode": "P003$ ",
"PlanName": "Plan3$ "
},
{
"PlanCode": "P004$ ",
"PlanName": "Plan4$ "
},
{
"PlanCode": "P005$ ",
"PlanName": "Plan5$ "
},
{
"PlanCode": "P006$ ",
"PlanName": "Plan6$ "
},
{
"PlanCode": "P007$ ",
"PlanName": "Plan7$ "
},
{
"PlanCode": "P007$ ",
"PlanName": "Plan7$ "
},
{
"PlanCode": "P008$ ",
"PlanName": "Plan8$ "
},
{
"PlanCode": "P009$ ",
"PlanName": "Plan9$ "
}
]
使用handlbar代碼如下:
var PLAN_METHOD = {
handlerData: function (planJSON) {
var templateSource = $("#plan-template").html();
template = Handlebars.compile(templateSource);
var context = planJSON;
plansHTML = template({planJSON:context});
$('#plans-div').html(plansHTML);
},
loadPlansData: function() {
$.get("http://localhost:41801/plan/getplans",null,this.handlerData)
}
};
$(document).ready(function() {
PLAN_METHOD.loadPlansData();
});
HTML模板如下所示:
<div id="plans-div" >
</div>
<script id="plan-template" type="text/x-handlebars-template">
<table >
<thead>
<tr>
<th>Plan Code</th>
<th>Plan Name</th>
</tr>
</thead>
<tbody>
{{#each Plans}}
<tr>
<td>{{this.PlanCode}}</td>
<td>{{this.PlanName}}</td>
</tr>
{{/each}}
</tbody>
</table>
</script>
Something'plansHTML'in handlebar javascript code is not getting popu與JSON日期行相關聯。請幫助
其中'plans-div'在您的html?這應該是一個ID。 – alsafoo
抱歉不知何故沒有添加上面的計劃div的HTML。它在那裏如下:
你能否更新你的問題以包含'plans-div' – alsafoo