Search code examples
jsrenderjsviews

jsRender - build 54 - render not defined


updated to build 54, every time I attempt to render, I get a "undefined" error. This is the function I am calling:

var div = $(template).render(_content);

If I rollback to build 53 everything works. Did a code diff between jsrender.js build 53 & build 54 and noticed on line 72 in build 53, the declaration render: $render, is missing from build 54. Is there a syntax change I didn't see in the online doc?


Solution

  • This syntax

    var renderedHtml = $("#myTmpl").render(myData);
    

    works correctly in build 54.

    See http://www.jsviews.com/#db.render.

    The intention of the $(xxx).render(myData) API is that xxx is either an HTML element or a selector - referencing in both cases a script element containing your template markup.

    If you have already compiled your template, e.g. from a string, then you should use the syntax myCompiledTemplate.render(myData). (See http://www.jsviews.com/#tmplrender).

    In build 53, writing $(myCompiledTemplate).render(data) was (spuriously) equivalent to the correct myCompiledTemplate.render(data) - but it was not performant (unnecessary instantiation of a jQuery object) and was incorrect usage. That syntax is not supported...

    Here is your updated jsfiddle: http://jsfiddle.net/w5vFd/2/