小程序for循环对象

<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
    })
  }
})



阅读更多

没有更多推荐了,返回首页