Basic template

I have a lot of new things, but I manage to get him to work with the textbook. But when I want to send this application to the base template, I find that I am stuck in the template. How do I access my model from my template? or even from the js file itself? I'm stuck here right now.

The main boiler panel refers to https://github.com/tbranyen/backbone-boilerplate

+5
source share
1 answer

For most javascript template libraries, templating takes place in two phases.

  • ( HTML) . " ", . .
  • ( HTML), "" , . HTML.

.

//Compile your template string into a function
//Happens 1 time only then you can cache the function
var templateFunction = _.template("<p>Your <%- part %> is so <%- description %></p>");

//Generate your output HTML with varying sets of data.
var html1 = templateFunction({part: "nose", description: "big"});
//html1 has "<p>Your nose is so big</p>";
var html2 = templateFunction({part: "cat", description: "fat"});
//html2 has "<p>Your cat is so fat</p>";

, JST, jade . " " - , . , , , : {model: myModel};. - <%= model.get("displayName") %>.

+4

All Articles