Assume I'm building a blog where the home page renders a list of blog posts. My question is how to pass a model to each child post view?
I have an index.hbs iterating through a collection
{{#forEach models}}
{{view "post_view" model=value model_name="story"}}
{{/forEach}}
I have a post_view.js
var BaseView = require('./base');
module.exports = BaseView.extend({
className: 'post_view',
initialize: function() {
console.log(this.model); //undefined
console.log(this.options.model); //undefined on client, logs model attributes on server
}
});
module.exports.id = 'post_view';
But it appears the model isn't set inside the post_view.js. If I do a {{json value}}
inside the {{forEach}}
loop I can see the JSONified output printed. What do I need to do to pass a model, do I need to manually construct it inside the view? Thanks!