Store a jsRender template in a separate js file

后端 未结 5 649
天涯浪人
天涯浪人 2020-12-14 19:24

Is it possible to store a jsRender template in a separate file?

I want to store it in a separate file and make a reference of it in my page.

something like t

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 19:47

    In case you're trying to load external templates from a local file, like I was, let me save you some frustration. Don't use the jQuery $.get() as recommended in balexandre's answer.

    Use $.ajax(), and set async: true and dataType: text, otherwise it gives you an error: elem.getAttribute is not a function. See my answer to Error when loading jsrender templates through AJAX for details.

提交回复
热议问题