Where is the checked property of task defined?


#1

I’m a newbie to Meteor, After I finish reading the tutorial, I have one question related to this step , this page says task has a property named checked,

if the checked property of a task is true, the checked class is added to our list item.

But to my understanding, a task has two properties: text and createdAt.

Where is the property checked defined? Thanks in advance.


#2

If you check the final js file here:

https://github.com/meteor/simple-todos/blob/master/simple-todos.js

its there on the collection… but it does not seem to be in the tutorial, at least that i can see.


#3

It seams that it does not exist in the beginning…

but after you do an update…

Tasks.update(this._id, { $set: {checked: ! this.checked} });

its there

read the part: “Checking off and deleting tasks”

dont forget with mongo, there is no predefined schema. you can add properties has you go along…


#4

Got it , thank you very much!

Mongo doesn’t require a predefined schema for a document, just like JSON, so we can add fields whenever we want.

So the checked property is add by the Tasks.update


#5

One more question.

When the browser loads the TODO web page the first time, the Tasks.update() doesn’t get called yet, all task have no property named checked, while simple-todos.html tries to get the value of checked, it won’t get a NullPointerException like in Java, instead, I guess, it will get a default value if checked doesn’t exist, right?


#6

if not mistaken it returns null, so that {{#if checked}} still works :smile:, null or false it will not be checked


#7

All clear now, thank you!