自定义组件数据更新问题
发布于 4 年前 作者 yanwan 6873 次浏览 来自 官方Issues

properties:{

calendarConfig:{

type:Object,

value:{}

},

calendar:{

type:Object,

value:{

currentType:‘start’,

dateType:{

start:{

value:’’,

choosed:true,

},

end:{

value:’’,

choosed:false,

},

},

                    }

            }

}    

choosedData(e){

let that = this,

{ calendar } = that.properties,

{ currentType,dateType } = calendar;

currentType = ‘end’;

that.setData({

calendar,

// ‘calendar.currentType’:currentType,

})

console.log(‘calendar’,calendar,currentType)

},

            

在开发工具开启es6转es5的情况下,

我在修改currentType 的值之后,对calendar进行了保存,发现这个currentType 没有更新,打印还是旧的值,

但是在setData用’calendar.currentType’:currentType,

或者将前面赋值的"currentType = ‘end’;" 改为 " calendar.currentType = ‘end’; "

却能成功更新这个值。

也试过在setData回调里打印,排除setData异步可能性。

想知道这是为什么导致的这种多层结构的数据更新整个字段时,修改的字段没有更新呢

代码片段:https://developers.weixin.qq.com/s/wqdPVomY7XdZ

回到顶部