Last active
August 29, 2015 14:03
-
-
Save wilkerlucio/1f5d54eaf21f9dcf92da to your computer and use it in GitHub Desktop.
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
| var Template = { | |
| compile: function(string, builder) { | |
| var rootNode = $(string); | |
| var map = {}; | |
| rootNode.find("[data-binding]").each(function () { | |
| var el = $(this); | |
| var bindingName = el.data("binding"); | |
| map[bindingName] = el; | |
| }); | |
| builder(map); | |
| return rootNode; | |
| }, | |
| fromId: function(id, builder) { | |
| var templateString = $("#" + id).html(); | |
| return Template.compile(templateString, builder); | |
| } | |
| }; | |
| var samplePerson = { | |
| name: "Walter White", | |
| email: "mrwhite@bitches.com" | |
| }; | |
| var personView = function(person) { | |
| return Template.fromId("person-template", function(map) { | |
| map.name.text(person.name); | |
| map.email.text(person.email); | |
| }); | |
| }; | |
| $("#template-demo").append(personView(samplePerson)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment