// pages/components/voucher-select/index.js Component({ /** * 组件的属性列表 */ properties: { columns:{ type:Array }, placeholder:{ type:String }, }, /**数据监听 */ observers: { columns: function (val) { let arrData = val.filter(x => x.type == true); this.setData({ forData:val, echoData:arrData }) }, }, lifetimes: { created: function(){ //在组件实例刚刚被创建时执行,注意此时不能调用 setData }, attached: function () { //在组件实例进入页面节点树时执行 }, ready: function () { // 在组件在视图层布局完成后执行 }, detached: function () { // 在组件实例被从页面节点树移除时执行 }, }, /** * 组件的初始数据 */ data: { show: false, forData:[], echoData:[], }, /** * 组件的方法列表 */ methods: { showPopup() { this.setData({ show: true }); }, onClose() { this.setData({ show: false }); }, onSelectChange(e){ var data = this.data.forData var index = e.currentTarget.dataset.index if(data[index].type === undefined || data[index].type == false){ data[index].type = true }else{ data[index].type = false } this.setData({ forData:data }) }, onConfirm(){ var data = this.data.forData let arrData = data.filter(x => x.type == true); this.setData({ echoData:arrData }) this.triggerEvent('change',arrData) this.setData({ show: false }); } } })