Javascript jsrender未在模板中显示函数返回
我有两个返回简单字符串的函数。两者都是注册的Javascript jsrender未在模板中显示函数返回,javascript,jquery,jsrender,Javascript,Jquery,Jsrender,我有两个返回简单字符串的函数。两者都是注册的 $.views.helpers({ parseDate: function (jsonDate) { if (jsonDate != null) { var date = new Date(parseInt(jsonDate.substr(6))); var newDate = $.fullCalendar.formatDate(date, "MM/dd/yyyy");
$.views.helpers({
parseDate: function (jsonDate) {
if (jsonDate != null) {
var date = new Date(parseInt(jsonDate.substr(6)));
var newDate = $.fullCalendar.formatDate(date, "MM/dd/yyyy");
return newDate;
}
},
renderPrimaryResource: function (PrimaryResource, LessonID) {
debugger;
$.ajax({
url: "cl/lb",
dataType: "json",
data: { id: PrimaryResource.ResourceID },
type: 'GET',
async: false,
success: function (data) {
var thumbnailImage = data[1];
return thumbnailImage;
}
});
}
});
我的jsrender模板调用这两个函数。parse date函数被调用并按其应该的方式返回。第二个函数被调用并返回一些东西,但是jsrender没有拾取它?不确定会发生什么,但它被完全忽略了
<script id="LessonDetailTemplate" type="text/x-jsrender">
{{for lessons}}
<div class="row lesson-block">
<div class="span4">
<h4>{{:LessonName}}</h4>
<span><strong>Due on <span>{{:~parseDate(DueDate)}}</span>
<br/>
<p>{{:LessonDescription}}</p>
</div>
<div class="span4">
<span">{{:~renderPrimaryResource(PrimaryResource, LessonID)}}</span>
</div>
</div>
{{/for}}
{{上课}
{{:LessonName}
到期日{{:~parseDate(DueDate)}
{{:LessonDescription}
以防有人无意中发现。问题实际上是ajax调用。不确定它到底是什么,但不能从ajax调用的成功部分返回字符串。按如下所示修改函数,效果良好
renderPrimaryResource: function (PrimaryResource, LessonID) {
debugger;
$.ajax({
url: "cl/lb",
dataType: "json",
data: { id: PrimaryResource.ResourceID },
type: 'GET',
async: false,
success: function (data) {
var thumbnailImage = data[1];
}
});
if(thumbnailImage != null){
return thumbnailImage;
}
}