【发布时间】:2015-03-16 15:05:26
【问题描述】:
我正在尝试将带有绑定助手的“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);
});
【问题讨论】:
-
我把return改成了Ember.Handlebars.helpers.view.helperFunction.call,但是helper还是不行。我尝试通过控制台注销传入的“选项”,但它们现在未定义。当我删除助手时,我会收到错误,因为视图需要一个“日期输入”助手。所以我删除了一个新的“日期输入”组件,错误就消失了。因此,由于我不能简单地将 View Helper 移植过来,我现在正试图弄清楚如何让进程在组件中工作。
-
在组件中嵌入“makeViewHelper”也不起作用。我怀疑这是一个新事物,尚未发布。我回到我的视图助手,发现它确实有一个'options' obj 传入,但它的属性比以前少了很多。这次的错误是 options.helperName (通常是 'view') 是未定义的。我错过了很多东西,比如 boundOptions、hashContexts、hashTypes 等