0
我已經在Ember視圖中包裝了一個bootstrap-datepicker,但我對結果並不滿意。有沒有更乾淨的方法來做到這一點?有沒有更好的方法來設置它?
App.DatepickerView = Ember.View.extend({
classNames: ['dp'],
didInsertElement: function() {
var _this = this;
this.$().datepicker({'format': 'M yyyy','minViewMode': 'months'})
.on('changeDate', function(e) {
var id = $(this).datepicker().data('date').replace(" ", "-");
_this.get('controller').transitionToRoute('month', App.Month.find(id));
});
this.$('.month.active').removeClass('active');
if (this.get('controller.controllers.month.content')) {
this.update();
}
},
update: function() {
var month = moment(this.get('controller.controllers.month.id'));
this.$().datepicker('hide');
this.$().datepicker('setDate', month.toDate());
this.$().datepicker('show');
}.observes('controller.controllers.month.content')
});
具體來說,我想
- 更慣用處理
changeDate
事件,無論是在我的模板或通過click
處理 - 解決數據更新,如果我們通過上一個月開始了數據綁定(目前我檢查是否設置了
controllers.month.content
,並更新日期選擇器didInsertElement
感謝您的任何建議!