Created
January 22, 2015 04:40
-
-
Save bmvakili/57f1fe8d77e77f24c0f0 to your computer and use it in GitHub Desktop.
handlebar example js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
var source = null; | |
var activeDashboardId = 0; | |
render = function() { | |
$.getJSON( | |
'/edens_group/test/list', | |
function(data) { | |
console.log(data); | |
for(datum of data) { | |
console.log("Num Dashboards: " + datum.numDashboards); | |
Handlebars.registerHelper("dashboard_link", function() { | |
var id = Handlebars.escapeExpression(this.id); | |
var name = Handlebars.escapeExpression(this.name); | |
var classAttribute = ''; | |
if (id == activeDashboardId) { | |
classAttribute = ' class="active"'; | |
} | |
return new Handlebars.SafeString('<li ' + classAttribute + '><a href="#/dashboards/' + id + '" rel="external">' + name + '</a></li>'); | |
}); | |
Handlebars.registerHelper("page_title", function() { | |
var name = ''; | |
for (dashboard of datum.dashboard) { | |
if (dashboard.id == activeDashboardId) { | |
name = dashboard.name; | |
} | |
} | |
return new Handlebars.SafeString(name); | |
}); | |
var template = Handlebars.compile(source); | |
$("section#footer").prev().append(template(datum)); | |
} | |
} | |
); | |
} | |
$.ajax({ | |
url : 'dashboard-content.handlebars', | |
cache: true, | |
success: function(data) { | |
source = data; | |
render(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment