从模型 Sencha Touch 更新 Datepickerfield

发布于 2024-12-21 10:27:54 字数 255 浏览 5 评论 0原文

我有一个模型和商店,它从我的表单字段中获取值。 我的表单包含文本字段、选择字段、日期选择字段和单选字段。

我从表单中获取值并用它们更新我的模型。当稍后我将模型加载到表单中时,这些值会重新出现在除日期选择器字段之外的所有组件上。

我使用本地存储代理。我检查了数据库中的值,日期显示为以下格式:“2011-12-13T18:30:00.000Z”

我认为这可能是问题所在。也许日期选择器字段不知道如何加载格式。我应该怎么办 ??

萨莎

I have a model and store that take in values from my form fields.
My form contains a textfield, selectfield, datepickerfield and radiofield.

I take the values from the form and update my model with them. When later I load the model into the form, the values reappear on all components EXCEPT the datepickerfield.

Im using a localstorage proxy. I checked the values in the database, the date shows in the following format : "2011-12-13T18:30:00.000Z"

I think this may be the problem. Maybe the datepickerfield doesnt know how to load the format. What should I do ??

Sasha

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

司马昭之心 2024-12-28 10:27:54

您可以使用下面的代码将该日期格式转换为其他格式。
最初设置日期模式,即

Date.patterns = {
    ISO8601Long : "Y-m-d H:i:s",
    ISO8601Short : "Y-m-d",
    ShortDate : "n/j/Y",
    LongDate : "l, F d, Y",
    FullDateTime : "l, F d, Y g:i:s A",
    MonthDay : "F d",
    ShortTime : "g:i A",
    LongTime : "g:i:s A",
    SortableDateTime : "Y-m-d\\TH:i:s",
    UniversalSortableDateTime : "Y-m-d H:i:sO",
    YearMonth : "F, Y"
};

然后按如下方式应用此日期模式,即

yourDate.format(Date.patterns.ISO8601Short);
yourDate.format(Date.patterns.FullDateTime);

希望它会有所帮助...

You can convert that date formats to other using the code below .
Initially set the date patterns , ie

Date.patterns = {
    ISO8601Long : "Y-m-d H:i:s",
    ISO8601Short : "Y-m-d",
    ShortDate : "n/j/Y",
    LongDate : "l, F d, Y",
    FullDateTime : "l, F d, Y g:i:s A",
    MonthDay : "F d",
    ShortTime : "g:i A",
    LongTime : "g:i:s A",
    SortableDateTime : "Y-m-d\\TH:i:s",
    UniversalSortableDateTime : "Y-m-d H:i:sO",
    YearMonth : "F, Y"
};

Then apply this date patterns as follows , ie

yourDate.format(Date.patterns.ISO8601Short);
yourDate.format(Date.patterns.FullDateTime);

Hope it will help...

贪了杯 2024-12-28 10:27:54

你告诉我的是格式化日期的方法,而不是如何做......
但日期仍然无法加载&格式错误。
不,实际上我找到了答案,这是你必须做的:

  1. 你的 showForm 控制器(在表单中加载日期)应该看起来像这样:
    showForm :函数(参数){

    //加载必要的模型
    var model = BReimb.stores.ListStore.getAt(params.index);
    
    //加载除datepickerfield之外的所有字段
    Ext.getCmp('formPane').load(model);
    Ext.getCmp('MainView').setActiveItem(1);
    
    //对于日期选择器字段 -->其中 Ext.getCmp('date') 是表单中我的日期选择器字段的 id
    
    if(model.data.date != "")
        Ext.getCmp('date').setValue(new Date(model.data.date));
    
  2. 要格式化日期,如果你使用 itemTpl 它应该是:
    itemTpl : '{date:date("d M Y")}'

希望这对某人有帮助:D

What you're telling me is the ways to format the date, not how to do it…
But the date still doesnt load & the format is wrong.
No actually I found the answer, this is what you have to do :

  1. Your showForm controller (to load the date in the form)should look something like this :
    showForm : function (params) {

    //load the model necessary
    var model = BReimb.stores.ListStore.getAt(params.index);
    
    //load all fields except datepickerfield
    Ext.getCmp('formPane').load(model);
    Ext.getCmp('MainView').setActiveItem(1);
    
    //for datepicker field --> where the Ext.getCmp('date') is the id of my datepicker field in the form
    
    if(model.data.date != "")
        Ext.getCmp('date').setValue(new Date(model.data.date));
    
  2. To format the date, incase ur using an itemTpl it shud be :
    itemTpl : '{date:date("d M Y")}'

Hope this helps someone :D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文