zoukankan      html  css  js  c++  java
  • js表单序列化时,非空判断

    在项目中,对于数据的传输一般需要非空的判断,而数据字段较多时一般直接将表单序列化,此时如何判断非空,如下

    因为将表单序列化时,数据格式为

    trainKind=1&trainKindCode=1&trainTypeCode=1&selfWeight=1&weight=1&volume=1&loadPrice=1&length=1&width=1&hight=11&remark=1

    所以可以将字段与对应的值分隔开,循环判断

    var data = $('#addTypeForm').serialize();
                    var msg = '';
                    console.log(data);
                    var array = data.split("&");
                    for (var i = 0; i < array.length; i++) {
                        var kwarr = array[i].split("=");
                        console.log(kwarr);
                        for (var j = 0; j < kwarr.length; j++) {
                        if (kwarr[j] == null || kwarr[j] == '') {
                            $("#msgs").html('请把必填信息填上');
                        $("#promptIdModals").modal();
                        $('#showMask', window.parent.document).show();
                            return false;
                        }
                        }  
                    }

    其中的console.log(kwarr)格式为:

    (2) ["trainKind", "1"]0: "trainKind"1: "1"length: 2__proto__: Array(0)
    list.do:57 (2) ["trainKindCode", "1"]
    list.do:57 (2) ["trainTypeCode", "1"]
    list.do:57 (2) ["selfWeight", "1"]
    list.do:57 (2) ["weight", "1"]
    list.do:57 (2) ["volume", "1"]
    list.do:57 (2) ["loadPrice", "1"]
    list.do:57 (2) ["length", "1"]
    list.do:57 (2) ["width", "1"]
    list.do:57 (2) ["hight", "11"]
    list.do:57 (2) ["remark", "1"]
  • 相关阅读:
    SAP S/4HANA extensibility扩展原理介绍
    SAP CRM系统订单模型的设计与实现
    使用nodejs代码在SAP C4C里创建Individual customer
    SAP Cloud for Customer Account和individual customer的区别
    Let the Balloon Rise map一个数组
    How Many Tables 简单并查集
    Heap Operations 优先队列
    Arpa’s obvious problem and Mehrdad’s terrible solution 思维
    Passing the Message 单调栈两次
    The Suspects 并查集
  • 原文地址:https://www.cnblogs.com/FanJava/p/9207586.html
Copyright © 2011-2022 走看看