underscore.js-templating

How to fetch data from Backbone collection to Template

走远了吗. 提交于 2019-12-23 04:08:15
问题 i am just writing a simple backbone program. But i am not getting how to fetch data from backbone collection to backbone template. Complete code is written below: <!doctype html> <html> <head> <title>Backbone tutorial</title> </head> <body> <div class="user">user</div> <div class="page"></div> <script type="text/template" id="user-list-template"> I am not able to get data on daya.key <h1> <%= data.key %> </h1> </script> <script type="text/javascript" src="jquery.js"></script> <script type=

How to evaluate javascript functions in underscore with mustache notation?

爱⌒轻易说出口 提交于 2019-12-22 17:59:10
问题 I want to do something like this: <script id="tmpl-books" type="text/template"> <ul> <% for (var i = 0; i < books.length; i++) { %> <% var book = books[i]; %> <li> <em><%= book.title %></em> by <%= book.author %> </li> <% } %> </ul> </script> in my code, but I am using JSP so I have to use the {{ }} notation, but when I do this {{ for(var... }} does not work. <script id="tmpl-books" type="text/template"> <ul> {{ for (var i = 0; i < books.length; i++) { }} <% var book = books[i]; %> <li> <em>{

How to display a JS object with underscore templates?

▼魔方 西西 提交于 2019-12-22 10:28:45
问题 I am tying to display a JS object of data using underscore templates. I can't seem to be able to work out how to drill through the object to get the country names or other date (for example tarrifType) and display it using my template. The object looks like this... var items = [ { "country": { "China": [ { "tarrifType": "China Pass", "fixLine": "23p", }, { "tarrifType": "Monthly plan", "fixLine": "3p", } ], "Australia": [ { "tarrifType": "Pay as you go", "fixLine": "73p" }, { "tarrifType":

Underscore templating: Can't get switch to work

拥有回忆 提交于 2019-12-22 01:59:03
问题 I can't get a simple switch statement working in my underscore template. It's using the value of a variable called UserType which I've checked exists by displaying it with <%= UserType %>. Code coming up: <% switch(UserType) { %> <% case 13: %> <button id="schoolButton" value="schools" class="gridChooser k-textbox">Schools</button> <% case 12: %> <button id="teacherButton" value="teachers" class="gridChooser k-textbox">Teacher</button> <% case 8: %> <button id="classButton" value="classes"

Underscore templating: Can't get switch to work

我怕爱的太早我们不能终老 提交于 2019-12-22 01:56:09
问题 I can't get a simple switch statement working in my underscore template. It's using the value of a variable called UserType which I've checked exists by displaying it with <%= UserType %>. Code coming up: <% switch(UserType) { %> <% case 13: %> <button id="schoolButton" value="schools" class="gridChooser k-textbox">Schools</button> <% case 12: %> <button id="teacherButton" value="teachers" class="gridChooser k-textbox">Teacher</button> <% case 8: %> <button id="classButton" value="classes"

Passing data to underscore for rendering not working

橙三吉。 提交于 2019-12-20 05:24:13
问题 I am trying to render an underscore template which is the one below div.col-md-12#english select(value="", class="form-control") option | Select Your Language Preference script(type="text/template" id="english-pref") <% if (selected === "US") { %> option(value="US", selected) | United States <% } else %> <% if(selected === "US"){ %> option(value="UK", selected) | United Kingdom <% } %> Here is my Backbone View code app.NotesView = Backbone.View.extend({ el: '#notes', events: { 'click #save':

combine html template files into one JS file

折月煮酒 提交于 2019-12-19 17:46:28
问题 I have HTML template files (underscore template syntax) These files are saved in HTML format so they would be easy to edit (IDE syntax highlight) I don't want to fetch them with ajax, but rather combine them all and include them as a js file. Using GULP as my task-runner, I would like it to somehow combine all the HTML to something like this, as a javascript file that I could include in my BUILD process: template_file_name is the HTML file name. var templates = { template_file_name : '..

Adding more, another loop to my Underscore template with a new backbone model?

℡╲_俬逩灬. 提交于 2019-12-11 14:27:29
问题 UPDATE : I have got my code working, of sorts, but I have two issues and one problem I am not sure how to fix. I will post my current code below. One The Clients append to the right section within the TimesheetData template. But it wraps the option tag within the ClientData template within another option . So I get : <select> <option> <option value="XX"> XXX </option> </option> </select> Now I know this is what it is designed to do, to have a root element but I can not seem to find a solution

Outputting directly to template with Embedded Javascript Syntax

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 12:00:15
问题 I'm using Backbone with Underscore templates. I have a JavaScript if() condition in my code that looks something like this: <div class='faces'> <% if(somevalue === true) { %> your face <% } else { %> my face <% } %> </div> However I find this syntax awkward and I really would like to use something like the following, even though it doesn't actually work (replaces entire document with the text): <div class='faces'> <% if(somevalue === true) { document.write("your face"); } else { document

Underscore Template Looping, Without A Loop?

[亡魂溺海] 提交于 2019-12-11 07:44:52
问题 This sort of follows on from another question I asked but the guy I think was trying to explain something else, or more likely I did not explain my self right. So all my backbone code is working, and displaying out the output right data. Now for this explain with my test data, I have 17 rows of inputs, but even without making a _.each loop, its looping around 17 times, which I just don't understand why? So my Backbone code, var TimeSheetModel = Backbone.Model.extend({ defaults: { Timesheetrow