//secondclass数组已经是从云数据库里获取的,并且也成功渲染到了页面上,但当我点击时,页面没法跳转,报错“Cannot read property 'secname' of undefined”
//wxml
<view class="hmly-content-text" wx:for="{{secondclass}}" wx:key="index" wx:for-item="item2" wx:if="{{item.name==item2.name}}" bindtap="navigatetoclassification">
{{item2.secname}}
</view>
//js
navigatetoclassification: function(e) {
// 获取当前点击的元素的索引
const index = e.currentTarget.dataset.index;
// 获取对应的secname值
const secname = this.data.secondclass[index].secname;
// 跳转到目标页面,并传递secname作为参数
wx.navigateTo({
url: '/pages/classification/classification?secname=' + encodeURIComponent(secname)
});
}