ember.js - How to check for dynamic route segment from view -
i have datepicker ui widget , i'm trying keep in sync routes. routes pretty straightforward:
/months /months/jan-2013 /months/feb-2013 ...
i'm having hard time updating datepicker if user starts out entering 1 of dynamic routes (e.g. /months/jan-2013
).
how can this? unfortunately, change date need use datepicker's api (i.e. can't use handlerbars helper , update html), think i'll need custom function in view. i've tried using observed properties, without success.
here's solution came with:
app.monthroute = ember.route.extend({ setupcontroller: function(controller, model) { controller.set('model', model); this.controllerfor('application').set('activemonth', model.get('id')); } });
now applicationcontroller
knows 'selected month'. can use in datepicker view's init set date correctly:
app.datepickerview = ember.view.extend({ didinsertelement: function() { var _this = this; $('#dp').datepicker({ 'format': 'm yyyy', 'minviewmode': 'months', }) .on('changedate', function(e) { $(this).datepicker('hide'); var id = $(this).datepicker().data('date').replace(" ", "-"), month = app.month.find(id); _this.get('controller').transitiontoroute('month', month); }); // right here: if (this.get('controller.activemonth')) { $('#dp').datepicker('setdate', this.get('controller.activemonth')); } } });
any other answers/suggestions welcome.
Comments
Post a Comment