小程序canvas遍历画线,只显示了一条线

小程序canvas遍历画线,只显示了一条线

应该在全部遍历结束再draw()

不能遍历一次就draw一次,这样的话只能显示最后一次的线条

drawLine:function(nodeArr){
    // console.log("划线了")
    amctx.setLineWidth(3)
    amctx.setLineCap('round')
    for(var idx in nodeArr){
      var node = nodeArr[idx]
      // console.log("是啥:" + node)
      if (!node.isNode){
        amctx.beginPath()
        console.log("色值:" + node.color)
        amctx.moveTo(node.x1, node.y1)
        amctx.lineTo(node.x2, node.y2)
        amctx.setStrokeStyle(node.color)
        amctx.stroke()

      }
    }
    amctx.draw() //遍历结束再draw

  },
原文地址:https://www.cnblogs.com/tufei7/p/12125022.html