Last active
May 30, 2017 15:12
-
-
Save CheezItMan/33b342b9d47e345482ff2682b62938d0 to your computer and use it in GitHub Desktop.
Example app.js using a Task model to create several instances.
This file contains 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
// /src/app.js | |
// Import jQuery | |
import $ from 'jquery'; | |
import _ from 'underscore'; | |
import Task from './models/task'; | |
var my_task = new Task({ | |
title: "Create a model", | |
completed: true | |
}); | |
// ready to go | |
$(document).ready(function() { | |
// Added Code | |
// Select the template using jQuery | |
var template_text = $('#taskItemTemplate').html(); | |
// | |
// Get an underscore template object | |
var templateObject = _.template(template_text); | |
// Use the underscore template function to compile the | |
// template and data into raw html. | |
var compiledHTML = templateObject(my_task.toJSON()); | |
// Checking the values of template & compiledHTML. | |
console.log(template_text); | |
console.log(compiledHTML); | |
// append the html to the unordered list. | |
$('.todo-items').append(compiledHTML); | |
// End of new code | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment