- 为什么我的mainname参数传到pgdetail页面是空值呢?
<view class="page"> <view class="page__bd"> <view class="weui-panel weui-panel_access"> <view class="weui-panel__hd">{{secname}}</view> <block wx:for="{{soundprogram}}" wx:if="{{secname == item.secname}}" > <view class="weui-panel__bd"> <navigator url="/pages/pgdetail/pgdetail?mainname={{encodeURIComponent(item.mainname)}}" class="weui-media-box weui-media-box_appmsg" hover-class="weui-cell_active"> <view class="weui-media-box__hd weui-media-box__hd_in-appmsg"> <image class="weui-media-box__thumb" src="{{item.cover}}" /> </view> <view class="weui-media-box__bd weui-media-box__bd_in-appmsg"> <view class="weui-media-box__title">{{item.mainname}}</view> <view class="weui-media-box__desc">{{item.describe}}</view> </view> </navigator> </view> </block> </view> </view> </view> // pages/pgdetail/pgdetail.js Page({ data: { }, onLoad: function(options) { console.log(options); // 打印整个options对象 // 解码传入的mainname参数 const mainname = decodeURIComponent(options.mainname); // 设置导航栏的标题 wx.setNavigationBarTitle({ title: mainname }); }, }) [图片]
03-22 - 我的云数据库集合里有一百多条记录,但小程序限制获取前20条,怎么样才能获取全部记录呢?
db.collection('secondclass').get({ success: res => { console.log('从secondtclass集合获取到的数据:', res.data) this.setData({ secondclass: res.data }) }, fail: err => { console.error('[firstclass集合] [查询记录] 失败:', err) } }) },
03-22 - 为什么显示secname undefined 呢?
//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) }); }
03-21 - 为什么我的云数据库数据没有渲染成功呢?
我建立了两个集合,firstclass和secondclass,我想让secondclass里对应的secname字段渲染到对应板块。比如firstclass和secondclass里都有name == 体育,如何将secondclass里name == 体育 的secname渲染到它对应的地方呢? 我这样写,firstclass的name是可以渲染成功的,但secondclass里的secname没有成功 <view class="hmly-content-scroll-item" wx:for="{{firstclass}}" wx:key="index" data-index="{{index}}" id="main-id-{{index}}"> <view class="hmly-top"> {{item.name}} <text class="icon-right"></text> </view> <view class="hmly-content"> <view class="hmly-content-text" wx:for="{{secondclass}}" wx:key="index" bindtap="navigatetoclassification" wx:if="{{item.name}} == {{item2.name}}"> {{item2.secname}} </view> </view> </view>
03-21 - 为什么secname没有渲染到页面上呢?
<view class="hmly-content-scroll-item" wx:for="{{firstclass}}" wx:key="index" data-index="{{index}}" id="main-id-{{index}}"> <view class="hmly-top"> {{item.name}} <text class="icon-right"></text> </view> <view class="hmly-content"> <view class="hmly-content-text" wx:for="{{secondclass}}" wx:key="index" wx:if="{{item2.name == item.name}}"> {{item2.secname}} </view> </view> </view> 为什么secname没有渲染成功呢?
03-21 - 为什么firstclass的数据没有渲染到页面上呢?
//mainpage.js wx.cloud.init() // 获取数据库引用 const db = wx.cloud.database() // 获取第一个集合的引用 const collection1 = db.collection('firstclass') // 获取第二个集合的引用 const collection2 = db.collection('secondclass') db.collection('firstclass').get({ success: res => { console.log('从firstclass集合获取到的数据:', res.data) // 使用res.data直接在wx:for中循环 this.setData({ firstclass: res.data }) }, fail: err => { console.error('[firstclass集合] [查询记录] 失败:', err) } }) Page({ /** * 页面的初始数据 */ data: { activeIndex:0, VerticalNavTop: 0, TabCur: 0, }, }) //mainpage.wxml <block wx:for="{{firstclass}}" wx:key="index"> <view class="hmly-left-title {{index === activeIndex ? 'hmly-active':''}}" data-index="{{index}}" data-id="{{index}}" bindtap="change"> {{item.name}} </view> </block>
03-19