在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
核心:使用wx:for="{{posts_key}}",用数组的形式来绑定多个的内容,利用for循环来反复调用后台数据,如果没用用posts_key了,那么对应的item_这种命名就是不可以的! Wxml <block wx:for="{{posts_key}}" wx:for-item="item" wx:for-index="idx" wx:key="idx"> <view catchtap="onPostTap" data-postId="{{item.postId}}"> <image src="{{item.images}}"></image> <text>{{item.content}}</text> </view> </block>
JS var postsData = require('../../data/skip-data.js') const app = getApp() Page({ data: { }, onLoad:function(options){ this.setData({ posts_key:postsData.postList }); }, })
Skip-data,js(这个脚本用来模拟本地数据库) var local_database = [ { content: "VIPKID 纯北美外教 代言人刘涛", images: "/images/[email protected]", postId: 0, }, { content: "哒哒英语 专属外教 代言人孙俪", images: "/images/[email protected]", postId: 1, }, { content: "51Talk 高校教材 代言人贾乃亮", images: "/images/[email protected]", postId: 2, }, { content: "VipJr 量身定制课 代言人姚明", images: "/images/[email protected]", postId: 3, }, { content: "以上都想试听", images: "/images/[email protected]", postId: 4, }, ] module.exports = { postList: local_database }
|
请发表评论