小程式for迴圈物件
阿新 • • 發佈:2018-12-30
<view class="container log-list">
<block wx:for="{{logs}}" wx:for-item="log" wx:key="*this">
<view class="classname">
<text class="log-item">{{index + 1}}. {{log}}</text>
</view>
</block>
</view>
var util = require('../../utils/util.js') Page({ data: { logs: [ ] }, onLoad: function () { var test = wx.getStorageSync('logs'); var tset1 = test || []; var test3 = function (log) { return util.formatTime(new Date(log)); } var test2 = tset1.map(test3); this.setData({ logs: test2 }) } })
作為一個新手,看不懂demo,就拆分了一下。我是看懂了。
然後就解決了我的問題。
<view class="container log-list"> <block wx:for="{{logs}}" wx:for-item="log" wx:key="*this"> <view class="classname"> <text class="log-item"> {{log.title}}</text> </view> <view class="classname"> <text class="log-item"> {{log.content}}</text> </view> <view class="classname"> <text class="log-item">{{log.url}}</text> </view> </block> </view>
Page({ data: { logs: [] }, onLoad: function () { //獲取網路資料 var test = [ { "title": "張三", "content": "張三現在不太高興", "url": "https://chongnb.com/mana/05563814469562242.jpg" }, { "title": "李四", "content": "李四可能很高興", "url": "https://chongnb.com/mana/05563814469562242.jpg" }, { "title": "王五", "content": "王五現在不太高興", "url": "https://chongnb.com/mana/05563814469562242.jpg" } ] //設定資料 this.setData({ logs: test }) } })