Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

循环添加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]);
                                        }
                                    }
                                }
                            }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...