收藏
回答

markers图标不显示啊

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不显示

最后一次编辑于  2018-11-17  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏投诉关注问题回答

1 个回答

  • 卢霄霄
    卢霄霄
    2018-11-17

    that.setData({

        markers: [{

            id: i,

            iconPath: "/images/buy.png",

            latitude: res[i].latitude,

            longitude: res[i].longitude,

            width: 50,

            height: 50

        }]

    })


    2018-11-17
    赞同
    回复 12
    • ABCdeful
      ABCdeful
      2018-11-17

      我知道应该这样写,但是我想在markers加入多个对象,所以用for循环生成多个对象

      2018-11-17
      回复
    • 卢霄霄
      卢霄霄
      2018-11-17回复ABCdeful

      那你应该push

      2018-11-17
      回复
    • ABCdeful
      ABCdeful
      2018-11-17回复卢霄霄

      push是什么,求教,谢谢

      2018-11-17
      回复
    • 卢霄霄
      卢霄霄
      2018-11-17回复ABCdeful

      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})

      2018-11-17
      回复
    • ABCdeful
      ABCdeful
      2018-11-17回复卢霄霄

      谢谢,你等我试验一下

      2018-11-17
      回复
    查看更多(7)