循环添加this.$set值都等于循环的最后一个值,是怎么回事

                <view
                            class="uni-column"
                            v-for="(con, indexCon) in item.select_question"
                            :key="indexCon"
                            :class="indexCon == item.select_question.length - 1 ? '' : 'borderMin E7Bottom'"
                        >
                            <text class="conarea color-575757">{{ con.input_title }}</text>
                            <input
                                type="text"
                                :maxlength="item.number_of_characters"
                                class="moreinput"
                                :placeholder="con.input_title"
                                :value="con.value"
                                :disabled="dis"
                                :name="item.question_id"                
                                @input="value => onKeyInputMore(value,item.question_id,item.select_question.length,indexCon)"
                            />
                        </view>

image.png
这个_this.template[j].select_question[a] 里面添加的value字段都等于allArr[b]最后循环的值?亲问怎么修改呢,我要value里面展示不同的值,后面的值不覆盖之前的值,而是循环的给input初始值?

for (let a = 0; a < _this.template[j].select_question.length; a++) {
                                for (var key in _this.infoVisaValue) {
                                    if (key == _this.template[j].question_id) {
                                        var allArr = _this.infoVisaValue[key].split('<|>');
                                        for (let b = 0; b < allArr.length; b++) {
                                            _this.$set(_this.template[j].select_question[a], 'value', allArr[b]);
                                        }
                                    }
                                }
                            }
阅读 2.7k
2 个回答

是你最里面那一层循环导致的,`
for (let b = 0; b < allArr.length; b++)这里每次循环一次,都会把前面的赋值覆盖掉,第一次为allArr[0],第二次是allArr[1],一直到最后一位,你想实现的是什么

好吧,终于有点明白你的意图了:“循环的给input初始值”

(_this.infoVisaValue[_this.template[j].question_id] || '')
.split('<|>') // 获取`_this.template[j].question_id`初始值列表
.forEach((initialVal, index) { // 遍历初始值给对应位置的`_this.template[j].select_question`元素赋值
    _this.$set(_this.template[j].select_question[index], 'value', initialVal);
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题