小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

84 lines
2.5 KiB

Page({
data: {
list:[],
children:[]
},
toggleExpand(e) {
const id = e.currentTarget.dataset.id;
const canGo = e.currentTarget.dataset.have;
// 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(!canGo){
wx.navigateTo({
url: '/pages/newdetail/newdetail?name='+id // 支持参数传递
// url: '/pages/detail/detail?name='+id // 支持参数传递
})
}
},
// 在生命周期函数中加载数据
onLoad(options) {
let that = this;
const s = options.name;
const eventChannel = this.getOpenerEventChannel(); //取到事件对象
wx.setNavigationBarTitle({ title: s });
eventChannel.on("getCartDatalist",data=>{//发布事件
that.setData({
list:data,
children: data.children //cartDataList为此页的数据模型
// this.setData({list:childIndex.children});
});
console.log(that.data.cartDataList,"我被传过来了");
});
console.log(eventChannel);
},
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;
console.log(childIndex);
if(childIndex.haveChildren){
wx.navigateTo({
url: '/pages/elselist/elselist', // 支持参数传递
// url: '/pages/detail/detail?name='+childIndex.id // 支持参数传递
success (res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('getCartDatalist', childIndex) //触发事件
}
})
}else{
console.log(childIndex.id);
wx.navigateTo({
url: '/pages/newdetail/newdetail?name='+childIndex.id // 支持参数传递
// url: '/pages/detail/detail?name='+childIndex.id // 支持参数传递
})
}
wx.showToast({
title: `点击了子项 ${childIndex.id}`,
icon: 'none'
});
},
})