收藏
回答

createSelectorQuery 返回是重复的信息是为什么?

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.createSelectorQuery() 客户端 6.7.2 2.0.4

- 当前 Bug 的表现(可附上截图)


- 预期表现

    只出现 select 选择的数据

- 复现路径


- 提供一个最简复现 Demo

this.query = wx.createSelectorQuery()
this.query.select(selector).boundingClientRect().exec(res => {
  console.log(selector,'=',res)
resolve(res[0]);
});

返回值是重复的数据:


回答关注问题邀请回答
收藏

2 个回答

  • 李飞.妙进
    李飞.妙进
    2018-10-21

    this.query = wx.createSelectorQuery().in(parent.$root.$mp.page);

    let that = this

    position(selector) {

    let that = this;
    return new Promise(function (resolve, reject) {
    that.query.select(selector).boundingClientRect().exec(res => {
            resolve(res[0]);
        });
    })
    }

    //调用时

    await this.position('#t01')


    2018-10-21
    有用
    回复 2
    • 李飞.妙进
      李飞.妙进
      2018-10-21

      原因找到了,应该是每一次查询时重新声明一次

      createSelectorQuery,改成下面的就可以了


      position(selector) {
      let that = this;
      let id = selector.substring(1)
      let query = wx.createSelectorQuery().in(that.parent.$root.$mp.page);
      return new Promise(function (resolve, reject) {
      query.select(selector).boundingClientRect().exec(res => {
      res.forEach((item)=>{
      if (item.id){
      if (item.id == id) {
      resolve(item);
      }
      }
      })

      });
      })
      }


      2018-10-21
      1
      回复
    • 卢霄霄
      卢霄霄
      2018-10-21回复李飞.妙进

      哦~

      2018-10-21
      回复
  • 卢霄霄
    卢霄霄
    2018-10-21

    多贴点代码呢 看看你selector怎么写的

    2018-10-21
    有用
    回复
登录 后发表内容