我希望它能够在页面中移动网址并获取下一个网址,依此类推,直到绘图完成为止
function linkedDrawing(canvas,url){
fetch(url)
.then((response)=> response.json())
.then((data)=>{
url = data.url;
alert(data.url);
const c = canvas.getContext('2d');
c.beginPath();
c.moveTo(data.x1, data.y1);
c.lineTo(data.x2, data.y2);
c.strokeStyle = data.col;
c.stroke();
})
}
}
linkedDrawing(linkedDrawingCanvas, "http://jacek.soc.port.ac.uk/tmp/ws/alpha.json")
答案 0 :(得分:0)
我已经用这种方式编辑了你的代码:
public async Task<IActionResult> Delete([FromBody] Dto data)
答案 1 :(得分:0)
return
来自该函数的fetch()
调用并安排下一次调用相同的函数,另请参阅multiple, sequential fetch() Promise
const canvas = document.getElementById("linkedDrawingCanvas");
const c = canvas.getContext('2d');
function draw(response) {
return response.json()
.then(data => {
console.log(data.url);
c.beginPath();
c.moveTo(data.x1, data.y1);
c.lineTo(data.x2, data.y2);
c.strokeStyle = data.col;
c.stroke();
if (data.url) {
return linkedDrawing(linkedDrawingCanvas, data.url).then(draw)
} else {
return "complete"
}
})
}
function linkedDrawing(canvas,url){
return fetch(url)
.then(draw)
}
linkedDrawing(linkedDrawingCanvas, "http://jacek.soc.port.ac.uk/tmp/ws/alpha.json")