I have two functions that return simple strings. Both are registered.
$.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;
}
});
}
});
My jsrender template calls both functions. The parse date function gets called and returns as it should. The second function gets called and returns something but jsrender doesn’t pick it up? Not sure what happens but it is completely ignored.
<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}}
Anyone have any ideas why this doesn’t render? The only thing I can think of is the ajax call but while debugging the template doesn’t continue until the function returns something. So I am at lost of what is going on.
Answering in case anyone stumbles upon this. The problem was in fact the ajax call. Not sure exactly what it was but you cannot return the string from the success part of the ajax call. Modified the function as follows and works fine.