账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    关于 js 内存指针指向的问题?
    25
    0
    小程序开发时有个联动的标签选择(如图)例如:第一次选择了(["麻辣拌(无汤带麻酱)", "酸甜麻辣拌(无麻酱)"])两个属性后,如果取消了其中一个属性,那根据我的条件判断,应该是替换相应的值,而不是新增。现在出现的问题是,每次根据type类型查找下标,每次都是-1。代码:checkAttribute: function (e) { let pre = 0; let obj = {}; let tempArr = this.pureData.tempArr; const values = e.detail.value; console.log("values(1386) => ", values); const types = this.data.curAttributesType; const curAttributes = this.data.curAttributes; curAttributes.forEach(item => { const isExist = values.some(cur => cur === item.name) if (isExist) { item.checked = true; } else { item.checked = false; } }); const myAtr = curAttributes.filter(item => item.checked === true); obj.type = types; obj.value = myAtr; if (this.pureData.tempArr.length > 0) { const typeIdx = tempArr.findIndex(item => { item.type === this.data.curAttributesType }); console.log("typeIdx(1404) => ", typeIdx); if (typeIdx != -1) { this.pureData.tempArr[`${typeIdx}`].value = myAtr; } else { this.pureData.tempArr.push(obj) } } else { this.pureData.tempArr.push(obj); } console.log("tempArr(1412) => ", this.pureData.tempArr); this.setData({ curAttributes: curAttributes, }); },
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    网站公告
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部