为什么在这个很小的示例中未调用.await函数?

http://jsfiddle.net/x2fkvsco/

的HTML

<h1>test</h1>
<div id="a"></div>
<div id="b"></div>


JS

d3.queue()
   .defer(a,1)
   .await(b,2);

function a(x){
    d3.select('#a').text("a is executing with x="+x);
}

function b(err,x){
   d3.select('#b').text("b is executing with x="+x);
}


输出量

test
a is executing with x=1

最佳答案

@altocumulus用他的有见地的评论击败了我,但是由于一个例子讲了千字:



<!DOCTYPE html>
<html>

<head>
  <script src="https://d3js.org/d3.v4.min.js"></script>
</head>

<body>
  <h1>test</h1>
  <div id="a"></div>
  <div id="b"></div>
  <script>
    var q = d3.queue()
      .defer(a, 1, 2)
      .await(b);

    function a(x, y, callback) {
      d3.select('#a').text("a is executing with x=" + x);
      callback(null, y);
    }

    function b(err, x) {
      d3.select('#b').text("b is executing with x=" + x);
    }
  </script>
</body>

</html>

关于javascript - d3.queue.await函数未调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44312383/

10-09 23:30