获取接口数据后,循环添加某属性,触发时consol.log()数据是正常的,但是在页面渲染时会偶尔出现添加的数据没有渲染在页面上(想要的效果是:设置一个默认选择的效果)
let spuAttr = that.data.spuAttr; let attrOption=spuAttr.attrOption; let optionArr=[]; for (let i = 0, len = attrOption.length;i<len;i++){ for (let j = 0, jLen = attrOption[i].attrOption.length; j < jLen; j++) { if (j == 0) { attrOption[i].attrOption[j].class = "attr-selected" ; optionArr.push(attrOption[i].attrOption[j].attr_option_id); } else { attrOption[i].attrOption[j].class = '' ; } } } that.setData({ spuAttr: spuAttr }); |