Collections and templates


#1

I have a collection of items which possess a “default” property that is a boolean. Like so:

Collection:

"libs": {
    "name": 		"i18next",
    "descript":	        "Description",
    "type": 		"text/javascript",
    "href":		"http://i18next.com/",
    "src":		"http://location.com",
    "dependencies":     [],
    "default": 	        false
    }

Template:

<template name="libsList">
   {{#each libs}}
      <div class="col-sm-4">
         <label class="checkbox-inline">
    	    <input 
    		type="checkbox" 
    		name="extlibs" 
    		class="extlibs"
    		id="{{name}}"
    		value="{{src}}" 
    		{{ isDefault }}
    	     >
    	     <a class="libname" data-toggle="tooltip" data-placement="bottom" title="{{descript}}" id="{{name}}" href="{{href}}">{{name}}</a>
    	  </label>
        </div>
    {{/each}}
</template>

Helper function:

Template.libsList.helpers({
  'libs': function() {
    return Lib.find();
  },
  'isDefault': function() {
   console.log(Lib.find({default:true}));
  }
});

Now i am trying to get the “default” property to show up as a checked checkbox if true or as an unchecked checkbox if false.

But when i evaluate that property, the fact of the matter is that it exists no matter what its value is. So it returns true every time.

How do we evaluate boolean properties within collections with helpers?


#2

Ok, i’m sorry. Don’t know where my head was…

Template.libsList.helpers({
  'libs': function() {
    return Lib.find();
  },
  'isDefault': function() {
    if (this.default) {
      return "checked";
    }
  }
});

#3

Or use the mongo $eq aggregation
http://docs.mongodb.org/manual/reference/operator/aggregation/eq/