在调试模式下跳过每个方法

时间:2014-02-17 14:23:26

标签: javascript jquery each

这是我正在测试的一些JavaScript:

var filters;
$(".arrow-up").unbind("click").click(function (event) {
    var clickedArrow = $(this);
    var id = clickedArrow.attr('data-id');
    var select = document.getElementById(id);
    var option = select.options[select.selectedIndex];

    var filters;

    $(".search").each(function () {
        var SearchText = this.value;
        var id;

        if (!checkEmpty(SearchText)) {
            switch (this.id) {
                case "one":
                    id = 1;
                    break;
                case "two":
                    id = 2;
                    break;
                case "three":
                    id = 3;
                    break;
                case "four":
                    id = 4;
                    break;
                case "five":
                    id = 5;
                    break;
                case "six":
                    id = 6;
                    break;
                case "seven":
                    id = 7;
                    break;
                case "eight":
                    id = 8;
                    break;
            }

            var filter = document.getElementById(id);
            var filterOption = filter.options[filter.selectedIndex].text;

            filters += '&col=' + filterOption;
            filters += '&col=' + SearchText;
        }
    });

    var cols;

    /* Get all of the drop downs for the columns */
    for (var i = 1; i <= 8; i++) {
        var txt;
        var colVal = document.getElementById(i);
        txt = colVal.options[colVal.selectedIndex].text;
        cols += '&col=' + txt;
    }

    var url = '/AccountManagement/SortAscend';
    var formData = {
        option: option,
        filters: filters,
        cols: cols
    }

    var posting = $.post(url, formData, function (data, textstatus) {
        //spinner = new Spinner(opts).spin(target);
        StartSpinner();
    }, "json");

    posting.done(function (data) {
        ReloadTable(data);
        StopSpinner();
    });

});

当我在chrome中调试它时,它会跳过$(".search").each(function() { 部分 - 它只是跳到方法的末尾,因此它永远不会超过任何八个项目,过滤器变量仍然是“未定义”我是不知道为什么。

1 个答案:

答案 0 :(得分:0)

请尝试这些更改,并告诉我是否仍然只是每个。因为我正如你所做的那样使用它们并且它完美地工作。也许我也会将开关更改为“关联数组”

var numbers = {"one":1,"two":2...};

然后

id = numbers[$(this).attr("id")]

但首先尝试下面的代码。

var filters;
$(".arrow-up").unbind("click").click(function (event) {
  var clickedArrow = $(this);
  var id = clickedArrow.data('id');
  var select = $('#'+id);
  var option = $(select + '> option:selected');

  var filters;

  $(".search").each(function () {
    var SearchText = $(this).val();
    var id;

    if (!checkEmpty(SearchText)) {
        switch ($(this)attr("id")) {
            case "one":
                id = 1;
                break;
            case "two":
                id = 2;
                break;
            case "three":
                id = 3;
                break;
            case "four":
                id = 4;
                break;
            case "five":
                id = 5;
                break;
            case "six":
                id = 6;
                break;
            case "seven":
                id = 7;
                break;
            case "eight":
                id = 8;
                break;
        }

        var filter = document.getElementById(id);
        var filterOption = filter.options[filter.selectedIndex].text;

        filters += '&col=' + filterOption;
        filters += '&col=' + SearchText;
      }
  });

  var cols;

  /* Get all of the drop downs for the columns */
  for (var i = 1; i <= 8; i++) {
    var txt;
    var colVal = document.getElementById(i);
    txt = colVal.options[colVal.selectedIndex].text;
    cols += '&col=' + txt;
  }

  var url = '/AccountManagement/SortAscend';
  var formData = {
    option: option,
    filters: filters,
    cols: cols
  }

  var posting = $.post(url, formData, function (data, textstatus) {
    //spinner = new Spinner(opts).spin(target);
    StartSpinner();
  }, "json");

  posting.done(function (data) {
    ReloadTable(data);
    StopSpinner();
  });
});