<block wx:for="{{lists}}" wx:key="{{index}}">
<input bindinput="bindKeyInput"></input>
</block>
<button class="add-li" bindtap='addList'>添加选项</button>
<button class="add-li" bindtap='delList'>删除选项</button>
// pages/shopactionadd/shopactionadd.js
Page({
/**
* 页面的初始数据
*/
data: {
lists: [{},{},{}],
collapse: false,
yes: "/pages/image/unchecked.png",
no: "/pages/image/singal.png"
},
// 增加新的样式
addList: function () {
var lists = this.data.lists;
var newData = {};
lists.push(newData)**;//实质是添加lists数组内容,使for循环多一次**
this.setData({
lists: lists,
})
},
// 减少新的样式
delList: function () {
var lists = this.data.lists;
lists.pop(); //实质是删除lists数组内容,使for循环少一次
this.setData({
lists: lists,
})
},
daytime() {
const collapse = this.data.collapse;
this.setData({
collapse: false,
})
},
activetime(){
const collapse = this.data.collapse;
this.setData({
collapse: true,
})
}
实质是添加lists数组内容,使for循环多一次