在开放微信小程序时,如果给数组某个元素赋值,为了能够能够在页面视图上即时显示,我们常这样做:
data: {
videos: <Video[]>[],//或<Video[]>new Array()
}
//----------
this.data.videos.push(video);
this.setData({
videos: this.data.videos
})
另外一种做法:
let i: Number = this.data.videos.length;
let tmp: string = 'videos[' + i + ']'; //tmp='videos[0]'
this.setData({
[tmp]: video
})