小程序可以动态渲染数据吗
发布于 6 年前 作者 xxiong 1104 次浏览 来自 问答

我想动态渲染以上数据 ,先采用随机方式取一个数字,然后加到正确的数字 ,采用这样的动态方式

rollData: function(realData, index = 0){
    let roundData, randomData;
    if(index == 0) {
      roundData = [1, 2, 3, 4, 5, 6, 7, 8, 9];
      roundData.splice(roundData.find((item, index) => {
        if (item === realData[index]) {
          return index;
        }
      }), 1)
      randomData = roundData[Math.floor(Math.random() * 9)];
    }
    else {
      roundData = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
      roundData.splice(roundData.find((item, index) => {
        if (item === realData[index]) {
          return index;
        }
      }), 1)
      randomData = roundData[Math.floor(Math.random() * 10)];
    }
    this.rollFunc(randomData, realData, roundData, index)
  },
  rollFunc: function(randomData, realData, roundData, index) {
    let arrData = `letter[${index}]`;
    console.log(randomData, realData, roundData, index)
    this.setData({
      [arrData]: randomData
    })
    if(randomData == realData[index]) {
      if(++index === (realData.length-1)) {
        console.log(33333)
        return;
      }else {
        this.rollData(realData, index)
      }
    }
    if(++randomData > 9 ){
      if(index === 0) {
        randomData = 1
      } else {
        randomData = 0
      }
    }
    this.rollFunc(randomData, realData,roundData,index)
  },

以上为自定义方法

this.rollData([1,2,3,4])

我在onload调用方法时,发现小程序并没有动态渲染

想问一下怎么实现这个功能呢  万分感谢(´▽`ʃ♡ƪ)

回到顶部