문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top