我有一个看起来像这样的剑道模板:
<script type="text/x-kendo-template" id="submitTemplate">
<table>
<thead>
<tr>
<th>Sequence</th>
<th>Pic</th>
<th>Name</th>
</tr>
</thead>
# for (var i = 0; i < data.length; i++) { #
<tr>
<td>#= Sequence #</td>
<td>#= Pic #</td>
<td>#= Name #</td>
</tr>
# } #
</table>
</script>
要在此处显示在剑道窗口中:
@(Html.Kendo().Window()
.Name("SubmitWindow")
.Title("Submit Concern")
.Visible(false)
.Modal(true)
.Draggable(true)
.Width(500)
)
我有一个通过这样的ajax调用获取json数据的函数:
function onButtonClick(e) {
e.preventDefault();
var submitTemplate = kendo.template($("#submitTemplate").html());
var modelData = this.dataItem($(e.currentTarget).closest("tr"));
var serviceURL = getPathFromUrl(window.location.href);
var wnd = $("#SubmitWindow").data("kendoWindow");
serviceURL = serviceURL.replace("NewConcerns", "GenerateRouteForConcern");
$.ajax({
url: serviceURL,
type: 'GET',
data: { concernid: modelData.id },
datatype: 'json',
success: function(result, status) {
wnd.content(submitTemplate(result));
wnd.center().open();
},
error: function() {
alert('Error in submitting route.');
}
})
}
数据存储在下面定义的 List 对象中:
public class ConcernRouteViewModel
{
public String Pic { get; set; }
public Int32 Sequence { get; set; }
public String Name { get; set; }
}
我的控制器如下:
[System.Web.Http.HttpGet]
public JsonResult GenerateRouteForConcern(int concernId)
{
List<ConcernRouteViewModel> crvmList = userSvc.GenerateRouteByConcernId(concernId);
return Json(crvmList, JsonRequestBehavior.AllowGet);
}
从我的控制器返回的 json 数据如下所示:
[{"Pic":"BBY","Sequence":1,"Name":"Bugs Bunny"},{"Pic":"DDK","Sequence":2,"Name":"Daffy Duck"},{"Pic":"EFD","Sequence":3,"Name":"Elmer Fudd"},{"Pic":"PLP","Sequence":4,"Name":"Pepe LePew"},{"Pic":"STC","Sequence":5,"Name":"Sylvester the Cat"}]
我想在我的剑道模板中显示 json 数据,但运气不佳。到目前为止,我尝试使用的所有东西都让我“未定义”。我认为我的主要问题在于 for 循环定义,但我不确定如何处理这样的对象列表。
任何帮助将不胜感激。