rendrjs/rendr

how to pass model to subview

Closed this issue · 4 comments

This is a question but figured Github is more heavily trafficked than Stack Overflow for this topic. 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!

Hi @jaredrada ,

Please post this on SO and link to it here. We're trying to push these sorts of questions more onto SO and to have Github be more with issues around the framework itself.

Thanks!

Thanks @crwang, thats understandable. I posted the question on SO... http://stackoverflow.com/questions/33463139/rendr-how-to-pass-model-to-subview-in-rendrjs-isomorphic-framework

Feel free to help answer since the SO traffic related to RendrJS is minimal!

Yeah, very minimal, that's why we're trying to push more that way! 😄

Cool, I also posted an answer. Would you mind closing out this Github issue too? Thanks!