Is resource nesting the only way to enable multiple dynamic segments?

ⅰ亾dé卋堺 提交于 2019-11-27 13:18:23

As i am the asker of the question you referenced, i am answering here. I have already updated my question that this is perfectly possible.

Your approach should work:

App.Router.map(function() {
  this.route('calendar_month', { path: 'calendar/:year/:month'});
});

All you have to add are the serialize and model hook implementations:

serialize: function(context){
    // i assume that you wrap year and month in an Object (maybe App.YearAndMonthObject)
    var ret = {
        year : context.get("year"),
        month : context.get("month")
    };
    return ret;
},
model : function(params){
    //somehow create your object from the params
    var model = App.YearAndMonthObject.create({
        year : params.year,
        month : params.month
    });
    return model;
}

This would also need a modification on your use of linkTo:

{{ linkTo calendar_month year month }}

...instead you would just use:

{{ linkTo calendar_month yearAndMonth }}

I think this an emberish way to deal with this.

Summary: So what are routes all about?

They are used to separate concerns. And in your case it seems so, that year and month are part of the same concern (=route). Therefore they should be wrapped together in an new Ember Object and your route (CalendarMonthRoute) should deal with this new object (maybe YearAndMonthObject or CalendarMonthObject?).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!