Frage

So I've got iron-router that returns Posts.find({_id: id}) in it's data function.

Now I'm wondering how I should handle this in the respective template.

My Question: What is the data context for Iron-Router?

In my template I would be doing something like this

{{#each some_context}}
{{content}} <br>
{{/each}}

So what would be the context I should be going with?

War es hilfreich?

Lösung

In your data function in iron-router do something like this

        var return_object = {
            all_posts: Posts.find({_id: id})
        }

        return return_object;

In your html file you can do something like this

<template name="all_posts">
    {{#each all_posts}}
        {{title}}
    {{/each}}
</template>

The router sets the data context to whatever you return in the data function. In this case you've returned return_object so you have access to all of it's fields. Structuring your return like this ensures that you can use the right data context when going through your each.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top