简体   繁体   English

如何为Sencha Touch的日期选择器设置日期

[英]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.

相关问题 Sencha触摸面板/日期选择器渲染问题 - Sencha Touch panel/date picker rendering issue Sencha Touch 2日期选择器组件和CSS:如何显示隐藏的列名? - Sencha Touch 2 date picker component & css: how to display hidden column names? 如何在 Sencha Touch 中定义日期类型? - How to define date type in Sencha Touch? Bootstrap Date Range Picker -&gt; Single Date Picker: 如何设置日期 - Bootstrap Date Range Picker -> Single Date Picker: How to set a Date 如何在日期选择器中设置最大日期? - How to set max date in date picker? 如何在Sencha touch的Picker中禁用特定行 - How to disable a particular row in Picker in Sencha touch 如何在第一个日期选择器选择DATE时在第二个日期选择器中设置DATE? - How to set DATE in second date-picker on selection of DATE from first date-picker? 如何在 angular 中设置日期选择器的默认范围 - How to set default range of date picker in angular 如何使用Clean jQuery Date and Time Picker Plugin设置从一个选择器到另一个选择器的日期-datetimepicker - How to set a date From one picker to another picker using Clean jQuery Date and Time Picker Plugin - datetimepicker 如何使用jQuery UI日期选择器设置当前日期? - how to set current date using jquery ui date picker?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM