繁体   English   中英

date.getTime 不是函数 extJS 日期字段列

[英]date.getTime is not a functioin extJS datefield column

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

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"
        }
    }
});

问题不在renderDate function 中,它的 function 名称应该出现在堆栈跟踪中。

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

您必须确保 model fields配置将date字段定义为类型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配置,无需自定义渲染器。

简而言之,需要存储/模型字段( type: "date" )日期格式来将从后端获得的任何日期字符串转换为dateFormat日期 object; 然后过滤器( type: "date" )仅适用于 javascript 日期 object; 最后,列 ( xtype: "datecolumn" ) format知道如何将 javascript 日期 object 转换回人类可读的格式(这可以并且通常与后端传输到 UI 的格式不同)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM