无法弄清楚JavaScript Undefined不是函数错误

时间:2015-04-01 01:22:04

标签: javascript jqgrid

以下代码抛出" Undefined不是函数"指示点的错误。

beforeSubmit: function(data, formid) {
            data.classid = data.classname; // Copy classname value to classid
            data.studentid = data.studentname; // Copy studentname value to studentid
            var studentRows = $studentTable.jqGrid('getRowData'),
                classRows = $classTable.jqGrid('getRowData'),
                enrollRows = $enrollTable.jqGrid('getRowData'),
                idx, dob, age, minage, maxage, stime, etime, st, et;
            for (idx in studentRows) {
                if (studentRows[idx].studentid === data.studentid) {
                    dob = studentRows[idx].dob;
                    break;
                }
            }
            if (typeof dob != "undefined") {
                age = calcAge(dob);
            }
            for (idx in classRows) {
                if (classRows[idx].classid === data.classid) {
                    minage = parseInt(classRows[idx].minage);
                    maxage = parseInt(classRows[idx].maxage);
                    stime = moment(coopStartDate.format('YYYY-MM-DD')+' '+classRows[idx].startTime, 'YYYY-MM-DD h:mm a');
                    etime = stime.clone().add(classRows['classMinutes'], 'minutes');
                    break;
                }
            }

            if (typeof age != "undefined" && typeof minage != "undefined" && typeof maxage != "undefined") {
                if (age < minage || age > maxage) {
                    return [false, "Your student is "+age+". The minimum age for this class is "+minage+", and the maximum age is " + maxage];
                }
            }

            if (typeof stime != "undefined" && typeof etime != "undefined") {
                for (idx in enrollRows) {
                    if (enrollRows[idx].studentid === data.studentid) {
                        st = moment(coopStartDate.format('YYYY-MM-DD')+' '+enrollRows[idx].startTime, 'YYYY-MM-DD h:mm a');
                        et = st.clone().add(enrollRows[idx].classMinutes, 'minutes');
                        // ERROR THROWN ON NEXT LINE
                        if ((stime.isBefore(et) || stime.isEqual(et)) && (etime.isAfter(st) || etime.isEqual(st))) {
                            return [false, "This student is already in a class at the time of the selected class."];
                        }
                    }
                }
            }
            return [false, "Something bad happened."];
        }

此代码是jqGrid表的一部分,并使用momentjs作为日期对象。我可以创建相同的momentjs对象并复制/粘贴相同的&#39;如果&#39;声明到JS控制台,它执行正常。此外,它之前的年龄/ minage / maxage测试工作完美。这个特定背景有问题,我无法弄清楚它是什么。

有人看到了什么问题吗?

1 个答案:

答案 0 :(得分:0)

我认为代替isEqual,您需要isSame

http://momentjs.com/docs/#/query/is-same/