列表信息布局是在components中,分别在首页和二级分类页面中展示,详情页布局都是一样的,所有想把首页和分类页的列表信息跳转到一个详情页面当中。在跳转时,首页报错如图,二级页面能够正常跳转。
首页代码:
<segment items="{{items}}" defaultIndex="0" bind:itemchanged="onSegmentItemChanged">
<view slot="0" class="segment-page work-page">
<recruitment wx:for="{{recruits}}" wx:key="key" wx:for-item="recruit" recruit="{{recruit}}" detailurl="../recuitmentd/recuitmentd?index={{index}}"></recruitment>
</view>
</segment>
分类页代码
<recruitment wx:for="{{recruits}}" wx:key="key" wx:for-item="recruit" recruit="{{recruit}}" detailurl="../../recuitmentd/recuitmentd?index={{index}}"></recruitment>
详情页js代码
onLoad(options) {
console.log(options);
let index = options.index;
let pages = getCurrentPages();
let indexpage = pages[0];
if(pages.length > 0){
indexpage = pages[1]
}
let recruits = indexpage.data.recruits;
let recruit = recruits[index];
this.setData({
index:index,
})
if(pages.length > 0){ indexpage = pages[1] } n你从首页跳到详情页,这里indexpage会取到详情页的page indexpage.data.recruits这个就是undefined,于是就报错了