function DIVline(array,fn)
{
var pts;
var index = 1 ;
var arr2 = [];
var driving = new BMap.WalkingRoute(map);
var promise = new Promise(function(resolve,reject){
resolve();
})
for(var i = 0 ;i<array.length-1;i++) {
(function(_i,_ary){
promise = promise.then(function(value){
driving.search(array[_i], _ary[_i+1]);
var content = _ary[_i+1].content;
var _promise =null;
(function(_val,_content){
_promise = new Promise(function(resolve,reject) {
driving.setSearchCompleteCallback(function(){
var _pts = driving.getResults().getPlan(0).getRoute(0).getPath();
var arr1 = [];
for(var t = 0; t < _pts.length ; t++ ){
arr1[t] = _pts[t];
arr1[t].content = _content;
}
if(_val && _val.length > 0) {
resolve(_val.concat(arr1));
}else {
resolve(arr1);
}
});
});
})(value,content)
return _promise;
});
})(i,array);
}
promise.then(function(pts){//最後執行
var polyline = new BMap.Polyline(pts);
map.addOverlay(polyline);
for(var t = 0; t < pts.length ; t++ ){
onsole.info(pts[t].content);
}
if(pts != undefined){
if(fn && typeof fn == 'function'){
fn(pts);
}
}
});
}
Promise 異步變同步
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Promise的順序執行
Greasy_Giant
2018-08-25 13:02:20
Promise易錯點
bc_tom
2018-08-25 06:03:45
Promise之all
Egret_or_Unity
2018-08-23 12:10:37
async/await深入學習
DPJune
2018-08-22 14:36:30
Promise,Ajax,fetch
钟小楼
2018-08-22 07:38:01
玩轉 AngularJS 的 Promise
烈火蜓蜻
2018-08-22 07:16:40
JavaScript異步操作彙總
Coco-LG
2018-08-22 07:00:34
在koa2中使用'presto-client連接presto數據庫,返回json
小白的2015
2018-08-22 05:50:08
JavaScript中的Promise對象
片刻清夏
2018-08-22 05:35:24
NodeJS-Promise、await、async異步變同步
jack_ldp
2018-08-22 05:31:39
Typescript 異步編程範式 Await/Async Deferred/Promise
__Lingyue__
2018-08-22 04:00:49
Promise簡單實現
AiceIce
2018-08-22 03:03:57
ES6-Promise
卫夫子
2018-08-22 02:51:15
JavaScript中Promise和setTimeout的區別
zhoulu_hp
2018-08-22 02:41:48
Promise的使用
itchosen
2018-08-22 01:23:01