首页 > 解决方案 > date.getTime 不是 extJS 日期字段列的功能

问题描述

在网格中的日期过滤器中,我收到了这个错误。

Uncaught TypeError: date.getTime is not a function
    at Object.clearTime (ext-all-rtl-debug.js?_dc=1591679946477:6514)
    at constructor.convertDateOnly [as _convert] (ext-all-rtl-debug.js?_dc=1591679946477:237750)
    at constructor.getCandidateValue (ext-all-rtl-debug.js?_dc=1591679946477:45385)
    at constructor.= [as _filterFn] (ext-all-rtl-debug.js?_dc=1591679946477:45406)
    at constructor.filter (ext-all-rtl-debug.js?_dc=1591679946477:45222)
    at ext-all-rtl-debug.js?_dc=1591679946477:45143
    at constructor.onCollectionRefresh (ext-all-rtl-debug.js?_dc=1591679946477:82919)
    at constructor.updateSource (ext-all-rtl-debug.js?_dc=1591679946477:83983)
    at constructor.setter [as setSource] (ext-all-rtl-debug.js?_dc=1591679946477:11193)
    at constructor.onFilterChange (ext-all-rtl-debug.js?_dc=1591679946477:83515)

这是我的专栏辩护。

"dataIndex" : "date",
            "text" : " Date",
            "minWidth" : 120.0,
            "xtype" : "datecolumn",
            "renderer" : "renderDate",
            "filter" : {
                "type" : "date"

  }

这是 renderDate 方法。

renderDate : function(val){
        debugger;
        val = new Date(val)
        val = Ext.Date.format(val,'d-M-Y H:i:s T'); 
        return val;
    },

任何人都可以帮助我解决这个问题以及如何解决它。谢谢是Advamce。

这是我的网格存储:

Ext.define("MyAPp.store.base.GridStore", {
    extend: "Ext.data.Store",
    alias:"widget.tGridStore",
    requires: ["Ext.data.proxy.Rest"],
    model: Ext.create('Ext.data.Model', {
        fields: [
            { name: 'name', type: 'String' },

        ]
    }),
    autoLoad: false,
    remoteSort : false,
    remoteFilter: false,
    proxy: {
        type: 'ajax',
        url: 'someURLa',
        actionMethods:{
            read:'POST'
        },  
        reader: {
            type: 'json',
            rootProperty: "data",
            totalProperty: "TotalCount"
        }
    }
});

标签: javascriptdateextjs

解决方案


问题不在于renderDate函数,否则它的函数名应该显示在堆栈跟踪中。

堆栈跟踪提示过滤器。问题的原因似乎是您将类型过滤器应用于date支持网格列的商店的模型字段。所述过滤器要求后备模型字段包含 javascript 日期对象(或 null),而不是(日期可解析的)非空字符串。加载到存储中的至少一条记录在date字段中不包含有效的 javascript 日期对象。

您必须确保模型fields配置将date字段定义为 type date,并且您提供正确dateFormat的日期字符串以便在加载时由商店正确地将日期字符串转换为 javascript 日期对象:

fields: [{
    name: "date",
    type: "date",
    dateFormat: "Y-m-d H:i:s" // whatever the format is in which you expect the date string from the backend
}]

如果该解决方案尝试无法为您解决问题,请发布您的商店/模型定义代码和您加载到商店中的数据。

附带说明,datecolumn允许您将日期显示格式作为format配置提供,无需自定义渲染器。

简而言之,需要 store/model 字段 ( type: "date")dateFormat将您从后端获得的任何日期字符串转换为 javascript 日期对象;然后过滤器 ( type: "date") 仅适用于 javascript 日期对象;最后列xtype: "datecolumn"format


推荐阅读