Last active
August 29, 2015 14:06
-
-
Save strack/414777c1eb35062ed58a to your computer and use it in GitHub Desktop.
how to add css classes appropriately - questions example
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
<head> | |
<title>questions</title> | |
</head> | |
<body> | |
<h1>Welcome to Meteor!</h1> | |
{{> hello}} | |
</body> | |
<template name="hello"> | |
<button id="btn">Click Me</button> | |
<p>You've pressed the button {{counter}} times.</p> | |
{{#each questions}} | |
<div class="question btn {{correctQ}}">{{title}}</div> | |
{{/each}} | |
</template> |
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
Questions = new Mongo.Collection('questions'); | |
if (Meteor.isClient) { | |
// counter starts at 0 | |
Session.setDefault("counter", 0); | |
Template.hello.helpers({ | |
counter: function () { | |
return Session.get("counter"); | |
}, | |
questions: function () { | |
return Questions.find(); | |
}, | |
correctQ: function () { | |
if (this.correct === "correct") { | |
return 'btn-success'; | |
} else { | |
return 'btn-danger'; | |
} | |
} | |
}); | |
Template.hello.events({ | |
'click #btn': function () { | |
// increment the counter when button is clicked | |
Session.set("counter", Session.get("counter") + 1); | |
}, | |
'click .question': function () { | |
var tempC = (this.correct == 'correct') ? 'incorrect' : 'correct'; | |
Questions.update(this._id, { | |
$set: { | |
correct: tempC | |
} | |
}); | |
} | |
}); | |
Meteor.startup(function () { | |
var fc = Questions.find().count(); | |
while (fc<5) { | |
Questions.insert({title: 'Question # ' + fcount}); | |
fc++; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment