javascript - 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"
}
}
});
解决方案
问题不在于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
推荐阅读
- c - 数组是如何在 K&R C 中初始化的?
- excel - 如何在格式化表中找到上次使用的列?
- javascript - 为什么无法在应用程序中打开时在 Safari 中执行超时?
- angular - Angular FormGroupArray 元素传递给组件
- javascript - 暂时隐藏 HTML / Bootstrap 元素正在改变它们的宽度
- java - 将 JRE 版本从 8u241 升级到 8u261 是在使用 LSSerializer 回写时从 xml 文件中删除命名空间(xmlns)标签
- twitter-bootstrap - Bootstrap - 列映射(类似于 row-cols-*)
- ios - 如何在 AWS Cognito 中设置排序键(辅助键)?
- python - mysql.connector.errors.ProgrammingError:处理格式参数失败;Python 'list' 无法转换为 MySQL 类型
- mysql - 将用户 ID 的 SQL 查询与第二个表的单独查询相结合