【问题标题】:Sencha Touch Store With Date FieldSencha Touch Store 带日期字段
【发布时间】:2011-11-24 07:03:24
【问题描述】:

我有一个带有日期字段和存储的模型,它从 XML 加载,日期字段与字符串相同。 sencha 会自动将其解析为 Date 还是我需要手动解析?

Ext.regModel('News', {
    idProperty: 'Id',
    fields: [
        { name: 'Id', type: 'int' },
        { name: 'Title', type: 'string' },
        { name: 'PostedOn', type: 'date' },
        { name: 'PostedBy', type: 'string' },
        { name: 'Details', type: 'string' }
    ]
});

var newsRemoteStore = new Ext.data.Store({
    model: 'News',
    sorters: [{
        property: 'PostedOn',
        direction: 'DESC'
    }],
    proxy: {
        type: 'ajax',
        url: BaseURL + 'News.php',
        reader: {
            type: 'xml',
            root: 'News',
            record: 'New'   
        }
    },
    getGroupString: function(record) {
        if (record && record.data.PostedOn) {
            return record.get('PostedOn').toDateString();
        }
        else {
            return '';
        }
    }
});

我问是因为日期字段是空的,即使 xml 响应中有日期,例如

<PostedOn>2011-07-04 16:00:19</PostedOn>

【问题讨论】:

    标签: model sencha-touch store


    【解决方案1】:

    Sencha Touch 1.1 版本支持 auto、string、int、float、boolean 和 date(参考Sencha Touch 1.1 API Docs

    【讨论】:

      【解决方案2】:

      不,sencha 仅支持 4 种数据类型:int、float、string 和 auto。

      您应该将日期字段设置为字符串,然后将其转换为 getGroupString 中的日期对象,以将其与另一个日期对象进行比较。在此处阅读所有相关信息:http://www.sencha.com/blog/ext-js-4-anatomy-of-a-model

      【讨论】:

        猜你喜欢
        • 2011-11-26
        • 2014-02-06
        • 2012-08-18
        • 1970-01-01
        • 2013-07-04
        • 2012-12-22
        • 1970-01-01
        • 2012-08-02
        • 1970-01-01
        相关资源
        最近更新 更多