我尝试实现 Ajax 表,但在尝试使用 fancygrid 实现“日期”类型变量时遇到错误。
当 json 数据向应用程序返回空日期时(特别是在添加新记录时刷新表之后)
index: 'pStartDate', title: 'Start Date', type: 'date', format: { read: 'd/m/Y', write: 'd/m/Y', edit: 'd/m/Y' } {"success":"true","data":[{"id":15,"pReport_id":6,"pTypeOfAssessment":null,"pApplicationName":null,"pStartDate":null,"pEndDate":null,"pApplicationURL":null,"pScope":null,"pStatusOfReview":null}],"totalCount":0}
示例:http://jsfiddle.net/t786hyhv/
当json数据返回带日期的数据时,在字段中输入空日期会导致错误。这也是通过选择但不添加新日期来新添加的记录。
{"success":"true","data":[{"id":35,"pReport_id":6,"pTypeOfAssessment":null,"pApplicationName":null,"pStartDate":"14/05/2017","pEndDate":"14/05/2017","pApplicationURL":null,"pScope":null,"pStatusOfReview":null}],"totalCount":1}
示例:http://jsfiddle.net/0noLomqy/
但是这些不会影响使用本地数据实现的 fancygrid。例如。 data:数据,而不是
data: {
proxy: {
api: {
create: 'URL',
read: 'URL',
update: 'URL',
destroy: 'URL'
}
}
}
注意:要让jsfiddle myjson返回,必须先访问myjson链接https证书,以防止跨域错误。
最佳答案
通过修改以下代码修复了错误:
case "date":
if(a.value != null || a.value.length != 0) {
var e = a.column.format,
f = Fancy.Date.parse(a.value, e.read, e.mode);
d.set(f);
}
break;
case "date":
if (e.format && e.format.read) {
if(e.editor.getDate().length != 0) {
var j = e.editor.getDate();
a = Fancy.Date.format(j, e.format.read, void 0, e.format.mode)
}
}
case "date":
return function(b) {
if (null === b || 0 === b.length) return "";
var c = Fancy.Date.parse(b, a.read, a.mode);
return b = Fancy.Date.format(c, a.write, void 0, a.mode)
}
关于javascript - 花式网格日期类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43963447/