收藏
回答

按顺序输入照片后,第2页调用照片后只显示第一张是为什么?

按顺序放入图片跳转到第二页进行处理,顺序传入照片跳转到第二页就只剩一张图了,然后不按顺序随机传入照片可以输出,怎么才能让第二页按输入的顺序读取照片呢

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

4 个回答

  • 知非
    知非
    2021-11-10

    好像没太懂,建议放上自己的代码然后让大家看看。

    2021-11-10
    有用 1
    回复 1
    • 阿偶呦喂
      阿偶呦喂
      2021-11-12
      Page1:
      Page({
        data: {
          pics: [],
          count: [1, 2,3,4,5,6],
          isShow: true
        },
        onLoad: function (options) {
          isShow: (options.isShow == "true" ? true : false)
        },
        chooseImage: function () {
          var _this = this,
            pics = this.data.pics;
          wx.chooseImage({
            count: 6 - pics.length,
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success: function (res) {
              // success
              var imgSrc = res.tempFilePaths;
              pics = pics.concat(imgSrc);
              wx.setStorageSync('image', res.tempFilePaths)
              if (pics.length >= 6) {
                _this.setData({
                  isShow : (!_this.data.isShow)
                })
              }else {
                _this.setData({
                  isShow: (_this.data.isShow)
                })
              }
              _this.setData({
                pics: pics
              })
            },
            fail: function () {
              // fail
            },
            complete: function () {
              // complete
            }
          })
        },
        previewImage: function (e) {
          var current = e.target.dataset.src
          wx.previewImage({
            current: current,
            urls: this.data.pics
          })
        },
        gotoPage: function (options) {
          wx.navigateTo({
                url: '..:A/A',//
       })
       },
      })
      Page2:
            // var sides = ['1.jpg', '2.jpg','3.jpg', '4.jpg','5.jpg', '6.jpg']
            var sides = wx.getStorageSync('image')
            console.log(sides)
      代码如上,源代码是直接读取了1-6图像,我想改为从本地相册传入1-6图像,但是跳转到第二页图像顺序就改变了,不知道我有没有说清楚。
      2021-11-12
      1
      回复
  • 不平
    不平
    2021-11-10

    可以分享一下代码片段吗,问题描述的不是很详细

    2021-11-10
    有用 1
    回复 1
    • 阿偶呦喂
      阿偶呦喂
      2021-11-12
      Page1:
      Page({
        data: {
          pics: [],
          count: [1, 2,3,4,5,6],
          isShow: true
        },
        onLoad: function (options) {
          isShow: (options.isShow == "true" ? true : false)
        },
        chooseImage: function () {
          var _this = this,
            pics = this.data.pics;
          wx.chooseImage({
            count: 6 - pics.length,
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success: function (res) {
              // success
              var imgSrc = res.tempFilePaths;
              pics = pics.concat(imgSrc);
              wx.setStorageSync('image', res.tempFilePaths)
              if (pics.length >= 6) {
                _this.setData({
                  isShow : (!_this.data.isShow)
                })
              }else {
                _this.setData({
                  isShow: (_this.data.isShow)
                })
              }
              _this.setData({
                pics: pics
              })
            },
            fail: function () {
              // fail
            },
            complete: function () {
              // complete
            }
          })
        },
        previewImage: function (e) {
          var current = e.target.dataset.src
          wx.previewImage({
            current: current,
            urls: this.data.pics
          })
        },
        gotoPage: function (options) {
          wx.navigateTo({
                url: '..:A/A',//
       })
       },
      })
      Page2:
            // var sides = ['1.jpg', '2.jpg','3.jpg', '4.jpg','5.jpg', '6.jpg']
            var sides = wx.getStorageSync('image')
            console.log(sides)
      代码如上,源代码是直接读取了1-6图像,我想改为从本地相册传入1-6图像,但是跳转到第二页图像顺序就改变了,不知道我有没有说清楚。
      2021-11-12
      回复
  • 没事
    没事
    2021-11-10

    可以看看你这个过程的代码吗?

    2021-11-10
    有用 1
    回复 5
    • 阿偶呦喂
      阿偶呦喂
      2021-11-12
      Page1:
      Page({
        data: {
          pics: [],
          count: [1, 2,3,4,5,6],
          isShow: true
        },
        onLoad: function (options) {
          isShow: (options.isShow == "true" ? true : false)
        },
        chooseImage: function () {
          var _this = this,
            pics = this.data.pics;
          wx.chooseImage({
            count: 6 - pics.length,
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success: function (res) {
              // success
              var imgSrc = res.tempFilePaths;
              pics = pics.concat(imgSrc);
              wx.setStorageSync('image', res.tempFilePaths)
              if (pics.length >= 6) {
                _this.setData({
                  isShow : (!_this.data.isShow)
                })
              }else {
                _this.setData({
                  isShow: (_this.data.isShow)
                })
              }
              _this.setData({
                pics: pics
              })
            },
            fail: function () {
              // fail
            },
            complete: function () {
              // complete
            }
          })
        },
        previewImage: function (e) {
          var current = e.target.dataset.src
          wx.previewImage({
            current: current,
            urls: this.data.pics
          })
        },
        gotoPage: function (options) {
          wx.navigateTo({
                url: '..:A/A',//
       })
       },
      })
      Page2:
            // var sides = ['1.jpg', '2.jpg','3.jpg', '4.jpg','5.jpg', '6.jpg']
            var sides = wx.getStorageSync('image')
            console.log(sides)
      代码如上,源代码是直接读取了1-6图像,我想改为从本地相册传入1-6图像,但是跳转到第二页图像顺序就改变了,不知道我有没有说清楚。
      2021-11-12
      回复
    • 没事
      没事
      2021-11-12回复阿偶呦喂
      你先在第一页看看顺序有没有问题,如果第一页没有问题但第二页有问题的话,你在第一页把数组转对象再存入
      2021-11-12
      1
      回复
    • 阿偶呦喂
      阿偶呦喂
      2021-11-13回复没事
      具体怎么操作呢
      2021-11-13
      回复
    • 没事
      没事
      2021-11-13回复阿偶呦喂
      你是指哪个部分呢?数组转对象的话是https://attacomsian.com/blog/javascript-convert-array-to-object
      2021-11-13
      回复
    • 没事
      没事
      2021-11-13回复阿偶呦喂
      一般来讲,你在wx.setStrogeSync()放的是什么顺序,然后到第二页就会是什么顺序,你现在只是把tempFilePaths放进去了,并不是放进你进行排序的数组
      2021-11-13
      回复
  • 阿偶呦喂
    阿偶呦喂
    2021-11-12

    Page1:

    Page({

      data: {

        pics: [],

        count: [1, 2,3,4,5,6],

        isShow: true

      },

      onLoad: function (options) {

        isShow: (options.isShow == "true" ? true : false)

      },

      chooseImage: function () {

        var _this = this,

          pics = this.data.pics;

        wx.chooseImage({

          count: 6 - pics.length, 

          sizeType: ['original', 'compressed'],

          sourceType: ['album', 'camera'], 

          success: function (res) {

            // success

            var imgSrc = res.tempFilePaths;

            pics = pics.concat(imgSrc);

            wx.setStorageSync('image', res.tempFilePaths)

            if (pics.length >= 6) {

              _this.setData({

                isShow : (!_this.data.isShow)

              })   

            }else {

              _this.setData({

                isShow: (_this.data.isShow)

              })  

            }

            _this.setData({

              pics: pics

            })

          },

          fail: function () {

            // fail

          },

          complete: function () {

            // complete

          }

       

        })

      },

      previewImage: function (e) {

        var current = e.target.dataset.src

        wx.previewImage({

          current: current,

          urls: this.data.pics

        })

      },

      gotoPage: function (options) {

        wx.navigateTo({

              url: '..:A/A',//

     })  

     },

    })

    Page2:

          // var sides = ['1.jpg', '2.jpg','3.jpg', '4.jpg','5.jpg', '6.jpg']

          var sides = wx.getStorageSync('image')

          console.log(sides)

    代码如上,源代码是直接读取了1-6图像,我想改为从本地相册传入1-6图像,但是跳转到第二页图像顺序就改变了,不知道我有没有说清楚。


    2021-11-12
    有用
    回复
登录 后发表内容