为什么不能重置data里的某些数据?
let initteam = {
p1:{name:"", bg:0, sg:0, dw:0, checked: 0},
p2:{name:"", bg:0, sg:0, dw:0, checked: 0},
p3:{name:"", bg:0, sg:0, dw:0, checked: 0},
p4:{name:"", bg:0, sg:0, dw:0, checked: 0},
};
let initsc = {
team1:"",
team2:""
};
Page({
data: {
team:{
},
sc: {
},
},
onLoad: function(option){
const eventChannel = this.getOpenerEventChannel()
const that = this
eventChannel.on('acceptDataFromOpenerPage', function(data) {
let all = data.data
initteam.p1.name = all[0]
initteam.p2.name = all[1]
initteam.p3.name = all[2]
initteam.p4.name = all[3]
that.clean() //这个可以设置初始data
})
},
clean() {
let that = this
that.setData({team:initteam})
that.setData({sc:initsc})
},
formSubmit(e){
let that = this
let sc = that.data.sc
let team = that.data.team
let score = e.detail.value
let first = 0
let fenshu = [0,0]
let allsc = that.data.score
for (const key in team) {
if (team.hasOwnProperty(key)) {
first += team[key].checked
}
}
if (sc.team1 == "" && team.p1.dw != true && team.p3.dw != true) {
console.log("请填分数")
} else if (first == 0) {
console.log("请填头游")
} else {
that.tichuscore(fenshu,team,sc)
that.addsc(allsc,fenshu)
that.setData({score:allsc})
that.clean() //这里就不能重置data的数据
} },
为什么onload里clean()可以设置data数据,forSubmit里clean()确无效?有没有什么方法在提交表单后把data里面team和sc的数据恢复?并且把所有switch、radio、input等表单的状态恢复。