0

There are different ways to invoke routes. I currently use Router.navigate( '/url', true ) in my view functions to trigger a route, but it also seems possible to trigger a route with an anchor tag with the url hash as the href attribute.

The way I render a collection to the screen has also something to do with it I guess. I have a global 'index' view that render a new subview for each item from the collection.

    render : function() {
        var self = this;

        $( this.el ).html( _.template( this.template, {} ) );

        this.collection.each( function( model ) {
            self.addOne( model );
        } );
    },

    addOne : function( model ) {
        var project = new TMRS.views.projects.Record( { model : model } );

        $( this.el ).append( project.render().el );
    },

Within the subview I trigger a route when a specific element is clicked, it works and it is easy as pie. But when I would decide to use anchors with hashes there is nu use for the subview anymore, because I can just iterate over the collections within my templates and handle urls with anchor tags.

I think it is better to use a single view for each record, but I don't know if it is the way to go. What do you guys think?

1 Answer 1

1

I ran into this same issue in my backbone project. I think it all comes down to scalability. Do you ever see the subview needing to become more complicated? If so then it would be better to go ahead keep the subview. If you go the templating solution then down the road you would just need to recreate the subview and wire it up again if you needed something more complicated than the anchors.

In my project, I did the template iterations for dropdowns. They will never become more complicated. (Most Likely).

Most other things I went ahead and did the subview so that I wouldn't have to perform that work later if needed. Also it doesn't really take to long to implement.

That's my 2 cents, but really I don't think there is a wrong way.

2
  • Your answer makes a lot of sense! Just today I decided to make the subview do more complicated stuff, so I will go with the subview.
    – Jacob
    Commented Jan 10, 2012 at 21:15
  • Glad to help! Good luck with your backbone project :D
    – Mike
    Commented Jan 10, 2012 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.