利用云开发改进题库
1.将题库转成对应的json模式后导入数据库
不要忘记改权限哦~
2.新建xiti页面
先做一个代码的搬运工,布局和样式照搬过来
<!--pages/xiti/xiti.wxml--> <view class="tip">当前第{{current}}题/共{{total}}题</view> <progress class="pro" percent="{{percent}}" border-radius="20" stroke-width="20"></progress> <view>题目:</view> <view class="item">{{subject.title}}</view> <radio-group bindchange="radioChange"> <view wx:for="{{subject.options}}" wx:key="index" class="item"> <radio value="{{item.code}}" checked="{{isSelect}}"/> <text>{{item.option}}</text> </view> </radio-group> <button type="primary" bindtap="next">下一题</button> <view wx:if="{{totalScore>-1}}" class="defen"> <view>您的得分为:{{totalScore}}分</view> <view bindtap="result" class="result">点击查看您的测评结果</view> </view>
/* pages/xiti/xiti.wxss */ .tip{ text-align: center; color: chocolate; margin: 15rpx; font-size: 42rpx; } .item{ margin: 20rpx; } .pro{ margin: 20rpx; } .defen{ margin: 20rpx; font-size: medium; text-align: center; } .result{ color:red; line-height: 30px; font-weight: bold; }
3.修改xiji.js代码
删除写死的题库,定义成一个空数组
![]()
获取数据库,并完成空数组的传值操作
实现效果:
![]()