I have a jQuery Template that is rendering a list of comments:
<script id="CommentTemplate" type="text/x-jquery-tmpl">
<开发者_开发问答;div class="Entry" id="${ID}">${Comment}</div>
</script>
This is being populated by a AJAX call and is working fine. I want to add a list of replies asynchronously. I would like to trap the event when this template content is rendered and append the replied to the Entry. Is there a way to call a JS function, say ShowResults(id) populated by ${ID} when each Entry is rendered?
Thanks
So after some digging I found a pretty elegant solution. You can pass an set of key value pairs to the template via the options parameter in the tmpl signature. I pass a function call as shown below:
$("#CommentTemplate").tmpl(result, {
LoadReplies: function (key) {
GetReplies(key);
}
}).appendTo("#CommentsListing");
Then in the GetReplies I do an AJAX call and apply to a second template. Worked like a charm.
加载中,请稍侯......
精彩评论