meteor Flashcards
meteor: To run your app on localhost, type
cd into it and type meteor
meteor: To create a new app, type
meteor create my_app
meteor: To render code into your html, type
{{myVar}}
meteor: To create a for loop in a template, type
{{#each items}}
{{> item}}
{{/each}}
meteor: To run code only on client, type it into
if (Meteor.isClient) {
}
meteor: meteor parses your template to find
head, body and template
meteor: templates can be rendered in HTML by typing
{{> templateName}}
meteor: To create an if statement in a template, type
{{#if}}
meteor: To pass data into templates from your JavaScript code, type
if (Meteor.isClient) { Template.body.helpers({ myCollection: [ { field: "String" }, { field: "String" }, ] }); }
meteor: To create a template, type
-template name=”templateName”>
…
-/template>
meteor: To create a database collection, type
MyCollection = new Mongo.Collection(“my-collection”);
note: remember new
meteor: To pass data into a template from a database query as a helper, type
Template.body.helpers({ getCollection: function () { return MyCollection.find({}); } })
meteor: Items inside collections are called
documents
meteor: To access the mongo console from the terminal, type
meteor mongo
meteor: To insert a document into a collection inside the mongo console, type
db.collectionName.insert({ field1: “string”, createdAt: new Date });
meteor: To listen to and handle an event in a template, type
Template.templateName.events({
“click .css-class”: function(event, template_instance)} {
event.preventDefault();
})
meteor: To access the value of an input field from a form submit event, type
event.target.fieldName.value
meteor: To clear the value of an input field from a form submit event, type
event.target.fieldName.value = “”;
meteor: To sort the data going into a template, type
MyCollection.find({}, {sort: {field1: -1}});
meteor: In a collection, every inserted document has a unique
_id
meteor: To access the _id of the event currently being handled, type
this._id
meteor: The update function on a collection takes
two arguments
meteor: To update a field of a document, type
MyCollection.update({field1: “value”}, {
$set: {field: “value”}
});
meteor: To delete a document, type
“click .css-class”: function () {
MyCollection.remove(this._id);
}