1

我刚开始研究backbone.js,我不确定使用路由器的最佳方式是什么。

App.Events = _.extend({}, Backbone.Events);

App.HouseDetailRouter = Backbone.Router.extend({
    routes: {
        '': 'main',
        'details/:id': 'details',
    },
    initialize: function() {

    },
    main: function() {
        App.Events.trigger('show_main_view');  
    },
    details: function(id) {
        model = App.houseCollection.get(id);
        App.Events.trigger('show_house', model);
    },
});

路由器应该像上面那样触发事件,然后让视图监听这些事件吗?

4

1 回答 1

0

This is actually not a bad way to use a router as it relegates the router to simply handling routes as opposed to business logic. What you might consider when using a router this way is to have a controller object listen to the router events then update the app's models. When the models change state the views would update.

于 2012-06-15T17:13:14.090 回答