javascript - 花式网格日期类型

标签 javascript jquery json ajax

我尝试实现 Ajax 表,但在尝试使用 fancygrid 实现“日期”类型变量时遇到错误。

  1. 当 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/

    相关文章:

    javascript - 如何循环遍历 javascript 中的子对象?

    c# - Response.Write Javascript 警报时出错

    javascript - 检查字符串是否包含任何图像标签的最简单方法是什么?

    jquery - 好奇为什么 <div title=***> 在我使用 jQuery .css 后变成了 oldtitle

    javascript - native 延迟加载图像回流(加载 ='"延迟”)

    javascript - 离线版 repl.it

    javascript - 使用 javascript 或 jQuery 添加/传递 Bootstrap 类到 'div'

    javascript - 使用 javascript/jquery 获取复杂嵌套 JSON 的各层数据

    Javascript - 通过键检索值,包括嵌套对象

    javascript - Scala 和 JavaScript 的 JSON.stringify