[英]How to set date to sencha touch's date picker
I am trying to set the date to date picker but not able to set the date. 我正在尝试将日期设置为日期选择器,但无法设置日期。 bellow is my chunk of sencha touch code.
下面是我的sencha触摸代码块。
this.scheduledDatePicker = Ext.create('Ext.field.DatePicker', {
//label: 'To',
//labelAlign: 'right',
//cls: 'form-block',
value: new Date(),
flex: 2.6,
});
and I am setting value after page load or get values from the database as using below code. 我在页面加载后设置值或使用以下代码从数据库中获取值。 I tried this many was as you can see commented code.
我尝试了很多,因为您可以看到注释的代码。 but cant able to set this value.
但无法设置此值。
var date= Ext.Date.format(Ext.Date.parse(this.rec.get('bookingDateTime'), "Y-m-d H:i:s"), "d/m/Y");
//var date= Ext.Date.parse(this.rec.get('bookingDateTime'));
//var date= this.rec.get('bookingDateTime');
this.scheduledDatePicker.setValue(date);
can anyone tell me why my code is not working or any solution for this issue? 谁能告诉我为什么我的代码不起作用或针对此问题的任何解决方案?
A datefield accepts a javascript date, however it seems you don't provide one. datefield接受一个javascript日期,但是您似乎没有提供它。
You should check what this.rec.get('bookingDateTime')
returns, and how to modify that field in such a way that you get a javascript date. 您应该检查
this.rec.get('bookingDateTime')
返回的内容,以及如何以获取JavaScript日期的方式修改该字段。
I expect that you already have a model, where you could specify that field to be of type date with a certain date format: 我希望您已经有了一个模型,可以在其中指定该字段为具有特定日期格式的date类型:
Ext.define('MyModel', {
fields: [{
name: 'bookingDateTime',
type: 'date',
dateFormat: 'Y-m-d H:i:s' // specify format that is received from the server
}]
});
Then ExtJS will do the conversion for you and you could just use setValue
without any parsing: 然后,ExtJS将为您进行转换,您可以使用
setValue
而不进行任何解析:
this.scheduledDatePicker.setValue(this.rec.get('bookingDateTime'));
If you don't have a model already, you can still read the string from bookingDateTime and parse it now and then and put it into the picker: 如果您还没有模型,您仍然可以从bookingDateTime中读取字符串,然后不时解析它,然后将其放入选择器中:
var date= Ext.Date.parse(this.rec.get('bookingDateTime'), "Y-m-d H:i:s");
console.log(date); // <- if date is null, format is not specified correctly.
this.scheduledDatePicker.setValue(date);
In both cases, console logging the interim result can help pinpoint down the issue: most of the time, the "parsed date" is null, because the format string does not match the date format received from the server. 在这两种情况下,控制台记录临时结果都可以帮助查明问题所在:在大多数情况下,“解析日期”为null,因为格式字符串与从服务器接收的日期格式不匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.