0

我正在尝试将带有绑定助手的“DateInputView”TextField 扩展移植到 HTMLBars。似乎“call()”已从“Handlebars.helpers.view”中删除,因此该助手不再起作用。我已经根据我读过的论坛尝试了几种语法更改,但没有任何效果。该字段是一个日期选择器,它在使用移动设备时切换到本机日历选择器。我看到了一个示例,其中绑定的帮助程序被集成到视图帮助程序代码中,所以使用一个 js 文件而不是两个,所以我现在正试图走这条路。代码如下。如果有人知道要为 HTMLBars 重做它,请告诉我。

// ../templates/avail/navigation.hbs
{{date-input id="checkin" valueBinding="controllers.avail.arrival" class="form-control date-picker"}}

// ../views/date-input.js
var DateInputView = Ember.TextField.extend({
  didInsertElement: function(){
    Ember.run.scheduleOnce('afterRender', this, this._setupDateInput);
  },
  _setupDateInput: function(){
    var _this = this;
    var type = Ember.$(this.get('element')).attr('type');
    // Set up Date Picker for object
    if( type === "input" ) {
      Ember.$(this.get('element')).datepicker({
        format: "yyyy-mm-dd",
        autoclose: true
      });
    }
  }
});
export default DateInputView;

// ../helpers/date-input.js
import DateInputView from '../views/date-input';

export default Ember.Handlebars.makeBoundHelper(function(options) {
  Ember.assert('You can only pass attributes to the `input` helper, not arguments', arguments.length < 2);

  var hash = options.hash,
    types = options.hashTypes,
    inputType = hash.type,
    onEvent = hash.on;

  delete hash.type;
  delete hash.on;

  hash.type = "input";

  if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
    hash.type = "date";
  }

  hash.onEvent = onEvent || 'enter';

  return Ember.Handlebars.helpers.view.call(this, DateInputView, options);
});
4

1 回答 1

0

我最终将这个 viewHelper 作为一个组件重新工作。

于 2015-04-01T18:36:09.127 回答