Sencha touch 2 Sencha 2-在视图中调用函数
这是配置对象中我的视图中的一个片段:Sencha touch 2 Sencha 2-在视图中调用函数,sencha-touch-2,Sencha Touch 2,这是配置对象中我的视图中的一个片段: xtype: 'fieldset', cls: 'loginFormText', items:[ { xtype: 'timepickerfield', label: 'Start', value: this.fromTime(), name: 'fromTime' },{ xtype: 'timepickerfield', label: '
xtype: 'fieldset',
cls: 'loginFormText',
items:[
{
xtype: 'timepickerfield',
label: 'Start',
value: this.fromTime(),
name: 'fromTime'
},{
xtype: 'timepickerfield',
label: 'End',
value: this.toTime(),
name: 'toTime'
}
]
在视图的底部,我有以下功能:
fromTime: function(){
var fromDate = new Date();
fromDate.setHours(12);
},
toTime: function(){
var toDate = new Date();
toDate.setHours(18);
}
但是我试图用“this.fromTime()”和“this.toTime()”来调用它们的方式不起作用,我该如何调用它们呢?你不能这样做。在创建时,这指的是全局窗口对象,而不是Sencha类。要解决此问题,必须在initialize()函数中执行。这应该行得通
Ext.define (MyApp.view.CoolView, {
xtype: 'coolview',
config: {
layout: 'fit'
},
initialize: function () {
var items = {
xtype: 'fieldset',
cls: 'loginFormText',
items:[
{
xtype: 'timepickerfield',
label: 'Start',
value: this.fromTime(),
name: 'fromTime'
},{
xtype: 'timepickerfield',
label: 'End',
value: this.toTime(),
name: 'toTime'
}
]
}
this.setItems(items);
},
fromTime: function(){
var fromDate = new Date();
fromDate.setHours(12);
return fromDate;
},
toTime: function(){
var toDate = new Date();
toDate.setHours(18);
return toDate;
}
})
干杯,奥列格行吗?因为在我看来,无论何时何地,我都不会归还任何东西。