2

在我的提交按钮单击处理程序结束时,Resharper 警告说,“并非所有代码路径都返回值。”

它对事件处理程序有什么期望?

尊重完全披露,这是事件处理程序:

   $("#submit_button").click(function() {
        // http://stackoverflow.com/questions/18192288/how-can-i-compare-date-time-values-using-the-jqueryui-datepicker-and-html5-time
        var begD = $.datepicker.parseDate('mm/dd/yy', $('#BeginDate').val());
        var endD = $.datepicker.parseDate('mm/dd/yy', $('#EndDate').val());
        if (begD > endD) {
            alert('Begin date must be before End date');
            $('#BeginDate').focus();
            return false;
        }
        else if (begD.toString() == endD.toString()) {
            var dteString = begD.getFullYear() + "/" + (begD.getMonth() + 1) + "/" + begD.getDate();
            var begT = new Date(dteString + " " + $('#BeginTime').val());
            var endT = new Date(dteString + " " + $('#EndTime').val());

            if (begT > endT) {
                alert('Begin date must be before End date');
                $('#BeginTime').focus();
                return false;
            }
        }

        $("#NumberOfResults").css("visibility", "visible");
        $("#NumberOfResults").html("Please wait...");

        EnableButton("submit_button", false);

        // If all are selected, don't enumerate them; just set it at "All" (change of case shows that the logic did execute)
        var deptsList = $('#depts').checkedBoxes();
        if (deptsList.length < deptsArray.length) {
            $('#deptHeader span').html(deptsList.join(", "));
        }
        else if (deptsList.length == deptsArray.length) {
            $('#deptHeader span').html("All");
        }
        // " "
        var sitesList = $('#sites').checkedBoxes();
        $('#sitesHeader span').html(sitesList.join(", "));
        if (sitesList.length < sitesArray.length) {
            $('#sitesHeader span').html(sitesList.join(", "));
        }
        else if (sitesList.length == sitesArray.length) {
            $('#sitesHeader span').html("All");
        }

        $('#hiddenDepts').val(deptsList);
        $('#hiddenSites').val(sitesList);
        var UPCs = $('#UPC').val();
        if (UPCs == "All") {
            $('#UPC').val("1"); // take everything (1 and greater)
        }

        var resultsText = jQuery.trim($("#spanNumberOfResults").text());
        if (resultsText != "") {
            $("#NumberOfResults").css("visibility", "visible");

            if (resultsText == "0") {
                $("#NumberOfResults").css("color", "red");
            } else {
                var href = '/@ConfigurationManager.AppSettings["ThisApp"]/CCRCriteria/LoadReport';
                // report_parms (sic) is referenced from LoadReport
                var report_parms = {
                    GUID: "@Model.GUID",
                    SerialNumber: "@Model.SerialNumber",
                    ReportName: "@Model.ReportName"
                };
                window.open(href, "report_window", "resizable=1, width=850, left=" + (screen.width / 2 - 425));
            }
        }
    }); // end of submit button click
4

2 回答 2

3

Resharper 不知道事件处理程序。

它看到你的函数有时return false有时不会返回任何东西,它会抱怨。

它没有意识到这种模式对于事件处理程序来说非常好。

于 2013-08-15T16:18:54.220 回答
2

忽略它。单击处理程序“可以”返回一个布尔值,指示是正常处理单击 (true) 还是忽略它 (false)。

Resharper 将函数中的任何返回视为它应该始终返回某些内容的线索。

于 2013-08-15T16:19:09.813 回答