Skip to content

Instantly share code, notes, and snippets.

Created September 1, 2013 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/6403481 to your computer and use it in GitHub Desktop.
Save anonymous/6403481 to your computer and use it in GitHub Desktop.
<head>
<title>todo</title>
</head>
<body>
<div class="wrapper">
{{> list}}
{{> addTodo}}
</div>
</body>
<template name="list">
<h1>Todo</h1>
<ul>
{{#each todoList}}
{{> todoItem}}
{{/each}}
</ul>
</template>
<template name="todoItem">
<li><input type="checkbox" class="done" {{#if done}}checked="checked"{{/if}}"></input> {{title}} </li>
</template>
<template name="addTodo">
<input type="text" id="newTitle"></input> <input type="button" class="addOff btn btn-primary" value="Add"></input>
</template>
<head>
<title>todo</title>
</head>
<body>
<div class="wrapper">
{{> list}}
{{> addTodo}}
</div>
</body>
<template name="list">
<h1>Todo</h1>
<ul>
{{#each todoList}}
{{> todoItem}}
{{/each}}
</ul>
</template>
<template name="todoItem">
<li><input type="checkbox" class="done" {{#if done}}checked="checked"{{/if}}"></input> {{title}} </li>
</template>
<template name="addTodo">
<input type="text" id="newTitle"></input> <input type="button" class="addOff btn btn-primary" value="Add"></input>
</template>
TodoItems = new Meteor.Collection("todoitems");
if (Meteor.isClient) {
Template.list.todoList = function () {
return TodoItems.find().fetch();
};
Template.addTodo.events({
'click .addOff': function () {
//alert("Creating new todo: " + $("#newTitle").val());
var newTodo = {
title: $("#newTitle").val(),
done: false
};
TodoItems.insert(newTodo);
}
});
Template.todoItem.events({
'change .done': function (a, b) {
TodoItems.update(this._id, {$set: {done: true}});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment