// When rending an underscore template, we want top-level
// variables to be referenced as part of an object. For
// technical reasons (scope-chain search), this speeds up
// rendering; however, more importantly, this also allows our
// templates to look / feel more like our server-side
// templates that use the rc (Request Context / Colletion) in
// order to render their markup.
_.templateSettings.variable = "rc";
// Grab the HTML out of our template tag and pre-compile it.
var template = _.template(
d3.select( "script.template" ).html()
);
// Define our render data (to be put into the "rc" variable).
var templateData = {
listTitle: "Olympic Volleyball Players",
somethingCompletlyDifferent: "Spanish inquisition!",
listItems: [
{
name: "Misty May-Treanor",
hasOlympicGold: true,
wins: 125
},
{
name: "Kerri Walsh Jennings",
hasOlympicGold: true,
wins: 156
},
{
name: "Jennifer Kessy",
hasOlympicGold: false,
wins: 55
},
{
name: "April Ross",
hasOlympicGold: false,
wins: 66
}
]
};
// sorting wins
// sorts by biggest first
var pobjedeSordted = _(templateData.listItems).sortBy(function(obj) { return -obj.wins });
//console.log(pobjedeSordted);
// Render the underscore template and inject it inside #main div
// in our current DOM.
d3.select("#main").html(
template( templateData )
);
////////////////////////////////////////////
// D3 stuff
////////////////////////////////////////////
var margin...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.