- 为什么在js里循环结束之后数据被重置了?
函数里面的points在循环结束之后就空了,在循环里面查看的时候有数据。 startNav: function(){ var that = this; var cen = this.data.center; var points = []; var dist = 0; var costsum = 0; //var marlen = this.data.markers console.log("markers: ",this.data.markers) for(var i=1;i<this.data.markers.length;i++) { console.log("已进入循环") cen.push({ longitude: this.data.markers[i].longitude, latitude: this.data.markers[i].latitude }) var key = config.Config.wxkey; var myAmapFun = new amapFile.AMapWX({key: key}); myAmapFun.getDrivingRoute({ origin: this.data.markers[i-1].longitude+','+this.data.markers[i-1].latitude, destination: this.data.markers[i].longitude + ',' + this.data.markers[i].latitude, success: function(data){ if(data.paths && data.paths[0] && data.paths[0].steps){ var steps = data.paths[0].steps; for(var i = 0; i < steps.length; i++){ var poLen = steps[i].polyline.split(';'); for(var j = 0;j < poLen.length; j++){ points.push({ longitude: parseFloat(poLen[j].split(',')[0]), latitude: parseFloat(poLen[j].split(',')[1]) }) } } } if(data.paths[0] && data.paths[0].distance){ dist = dist + data.paths[0].distance; console.log("距离",i,": ",dist," 类型为:",typeof data.paths[0].distance) } if(data.taxi_cost){ costsum = costsum + parseInt(data.taxi_cost); console.log("花费",i,": ",costsum," 类型为:",typeof data.taxi_cost) } }, fail: function(info){ } }) } console.log(points) that.setData({ polyline: [{ points: points, color: "#0091ff", width: 6 }], distance: '总路程' + dist + '米', cost: '打车约' + costsum + '元', center: cen }); }
2020-04-29 - 表单提交可以不使用button吗?
主要是觉得botton样式不好改变
2020-04-28 - 如何通过一个按钮获得两个输入框的值?
[图片] 如图,我想要的效果是点一下添加可以直接获得上面两个输入框的值,就是能不能只用一个函数。而不是通过每个输入框绑定的函数获取。
2020-04-28