Giter VIP home page Giter VIP logo

Comments (2)

BorisMoore avatar BorisMoore commented on May 18, 2024

Difficult to answer without knowing how you are 'ajaxing in' your templates. One way, which I would encourage, is to create a remote script file to load the templates as named templates, from strings:

Mytemplates.js:
$.template( "rowTemplate", “<tr>…</tr>” ); 
$.template( "liTemplate", “<li>…</li>” );

Then either include it statically, as <script src=”mytemplates.js” …> or use jQuery.getScript or equivalent to load dynamically. Render as named templates using $.tmpl("rowTemplate", data) or {{tmpl(data) "liTemplate"}}.

Can you test whether this approach works for you?

from jquery-tmpl.

jwynveen avatar jwynveen commented on May 18, 2024

That method works. However, I found a more efficient way to do it. When I receive the html response from my ajax call that has all of the templates in it, I use $('script', response).each(..) to loop through every <script> tag in the file and create a named template for each based on their id attribute.

from jquery-tmpl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.