Page({ data: { list:[], children:[] }, toggleExpand(e) { const id = e.currentTarget.dataset.id; const list = this.data.list.map(item => { if (item.id === id) { return { ...item, haveChildren: !item.haveChildren }; } else { return { ...item, haveChildren: false }; } }); this.setData({ list }); if(!e.currentTarget.dataset.haveChildren){ wx.navigateTo({ url: '/pages/detail/detail?name='+id // 支持参数传递 }) } }, // 在生命周期函数中加载数据 onLoad(options) { wx.showToast({ title: `点击了子项 ${options.name}`, icon: 'none' }); const s = options.name; wx.request({ url: 'https://keytest.aik518.com/prod-api/work_key/obd/key/type_blue?blueName='+s, method: 'GET', // 请求方法 success: res => { this.setData({ list:res.data.data // list: res.data.map(item => ({ // ...item, // isExpanded: false, // bgColor: '#fff' // })) }) } }) }, refresh: function(e) { wx.navigateTo({ url: '/pages/detail/detail?id=1&name=example' }); }, // 点击事件处理函数 handleItemClick: function (e) { // const index = e.currentTarget.dataset.index; // 主列表索引 // const subIndex = e.currentTarget.dataset.subIndex; // 子列表索引 // const subItem = this.data.list[index].sublist[subIndex]; // wx.showToast({ title: `点击了 ${subItem.name}`, icon: 'none' }); const childIndex = e.currentTarget.dataset.childIndex; // const {parentIndex, childIndex} = e.currentTarget.dataset // const childData = this.data.list[parentIndex].children[childIndex] // const childId = e.currentTarget.dataset.child; if(childIndex.haveChildren){ this.setData({list:childIndex.children}); }else{ wx.navigateTo({ url: '/pages/detail/detail?name='+childIndex.id // 支持参数传递 }) } wx.showToast({ title: `点击了子项 ${childIndex.id}`, icon: 'none' }); }, })