var Bmob = require( '../../utils/bmob.js' ); var app = getApp(); Page({ data: { longitude: "" , latitude: "" , markers: [], controls: [{ iconPath: '/images/address.png' , position: { left: (app.globalData.windowWidth / 2) - 20, top: (app.globalData.windowHeight - 40) / 2 - 38, width: 40, height: 40 } }, { id: 1, iconPath: '/images/positioning.png' , position: { left: 20, top: 20, width: 40, height: 40 }, clickable: true } ] }, staticData: {}, onShow() { this .getLocation(); }, onReady: function (e) { var that = this ; this .mapCtx = wx.createMapContext( 'Map' ); const query = Bmob.Query( "customerInfo" ); query.find().then(res => { console.log(res) for ( var i = 0; i < res.length; i++) { that.setData({ markers: { id: i, iconPath: "/images/buy.png" , latitude: res[i].latitude, longitude: res[i].longitude, width: 50, height: 50 } }) console.log(that.data.markers) } }); |
图片上是markers的值,但是为啥markers不显示
that.setData({
markers: [{
id: i,
iconPath:
"/images/buy.png"
,
latitude: res[i].latitude,
longitude: res[i].longitude,
width: 50,
height: 50
}]
})
我知道应该这样写,但是我想在markers加入多个对象,所以用for循环生成多个对象
那你应该push
push是什么,求教,谢谢
let markers = []
for
(
var
i = 0; i < res.length; i++) {
let marker = {
id: i,
iconPath:
"/images/buy.png"
,
latitude: res[i].latitude,
longitude: res[i].longitude,
width: 50,
height: 50
}
markers.push(marker)
}
that.setData({markers:markers})
谢谢,你等我试验一下