[solved] How to display {{#each}} based on criteria? (Probably super simple solution)

Okay, wow, I’m not seeing something. :frowning:
This seems to be such a simple thing to do:

Target

  1. I have two collections (lists & cards)
  2. I can create new lists and give a title to them
  3. I can create new cards and give a title to them
  4. I want to display some cards in list A, some cards in list B and some in list C
  5. To do this each card has a select field…
  6. …that (when changed) adds the title of the selected list to the corresponding card-document.

Based on this, can’t I somehow just do this in my list-templates?

<template name="list">
	<div class="list">
		<div class="list__title">{{title}}</div>
		<ul class="list__content">
			{{#each cards thatMatchTheListTitle}}
				{{> card}}
			{{/each}}
		</ul>
	</div>
</template>

Example:

It’s probably easier to look at it:
http://mb_baustellen.meteor.com/

Problem:

As you can see, the list-titles are attached correctly.
But in the lists all the cards are shown. I have no clue how to filter the {{#each}} based on the attached list-names.

Any help of push in the right direction?

EDIT nvm your using 1 template

Not sure if I understand 100% correctly but it sounds like you just need to write the cards Template helper method in such a way that it does the filtering for you, i.e. something like

return Cards.find(...).fetch().filter(function(card){ return trueIfCardMatchesTheListTitle(); });

or even without call to Array.filter() if you can just use a regular MongoDB / Minimongo selector expression to the find call!

1 Like

I made a simple pad http://meteorpad.com/pad/R5igEWZ4YASEr8dNh/each

Cards have a listId field

2 Likes

@seeekr,
@suburbio:
Wow, you guys are the best! :smile:

Problem solved.

I went with Seeekr’s advice, because that was what felt like the missing puzzle-piece to me:

In the end I just wrote:

var list = Lists.findOne(this._id);
var listTitle = list.title;

return Cards.find({list: listTitle});

http://mb_baustellen.meteor.com/

@suburbio
Thanks for introducing me to meteorpad :open_mouth:
Incredably cool!