创建无法获取所有值的多选功能

时间:2017-01-29 18:38:54

标签: javascript arrays function built-in

好的,所以这个问题要求我根据鼠标坐标和每个文本框的尺寸创建一个函数,但我不知道如何包含每个实例,其中至少有一个点触及鼠标的开始和结束行

function multiSelection(dimensions, tasks, mouseCoordinates) {
  var inDrag = [];
  var width = dimensions[0];
  var height = dimensions[1];
  var spaceHeight = dimensions[2];

  if (mouseCoordinates[0][1] > mouseCoordinates[1][1]) {
    var LineStart = mouseCoordinates[1][1];
    var LineEnd = mouseCoordinates[0][1];
  } else {
    var LineStart = mouseCoordinates[0][1];
    var LineEnd = mouseCoordinates[1][1];
  }

  var pos = 0
  for (var i = 0; i <= tasks.length; i++) {
    pos = pos + height + spaceHeight
    if (LineStart < pos && pos < LineEnd) {
      inDrag.push(tasks[i]);
    }
  }
  return inDrag;
}

console.log(
  multiSelection(
    [135, 9, 1],
    ["Task 1", "Task 2", "Task 3", "Very Important Task", "Not So Important Task", "Yet Another Task", "The last task"],
    [ [132, 42], [35, 13] ]
  )
);

1 个答案:

答案 0 :(得分:0)

我为可能的场景测试了您的代码并对其进行了评论;看一看。 我不确定你是否在问一个值得留在StackOverflow上的实际问题,但无论如何,你的输入都有问题。

Task task = restService.GetRequestAsync(articleAdr, articleParams);
var response = await Task.WhenAny(task, Task.Delay(1000, cts.Token));