const app = getApp() Component({ properties: { level: { type: Number, value: 3, }, value: { type: String, value: '', }, }, data: { imageUrl: app.globalData.imageUrl, Timestamp: app.globalData.Timestamp, show: false, options: [], fieldNames: { text: 'label', value: 'value', children: 'children', }, }, lifetimes: { attached() { this.getArea() }, }, methods: { handleShow() { this.setData({ show: true, }) }, getArea() { const { level } = this.data wx.ajax({ method: 'GET', url: '/js/area.json', data: {}, isJSON: true, }).then((res) => { if (level === 1) { res.forEach((item: any) => { delete item.children }) } if (level === 2) { res.forEach((item: any) => { item.children.forEach((child: any) => { delete child.children }) }) } this.setData({ options: res, }) }) }, onFinish(e: any) { this.triggerEvent('change', e.detail.selectedOptions) this.setData({ show: false, }) }, onClose() { this.setData({ show: false, }) this.triggerEvent('cancel') }, }, })