IronRouter extending data option on route controller

前端 未结 4 1702
清酒与你
清酒与你 2021-02-20 13:16

Is there a way to extend the data option when using IronRouter and the RouteController, It seems like it gets overridden when I inherit from a super co

4条回答
  •  [愿得一人]
    2021-02-20 13:39

    I use something similar to this in a production app:

    Router.route('/test/:testparam', {
        name: 'test',
        controller: 'ChildController'
    });
    
    ParentController = RouteController.extend({
        data: function() {
            console.log('child params: ', this.params);
            return {
                foo: 'bar'
            };
        }
    });
    
    ChildController = ParentController.extend({
        data: function() {
            var data = ChildController.__super__.data.call(this);
            console.log(data);
            return data;
        }
    });
    

    Using __super__ seems to do the trick!
    You can than use _.extend to extend the data (http://underscorejs.org/#extend)

提交回复
热议问题