Applet: use curly braces data processing

demand

I got from the rear end of a list of data, the page is rendered to the cycle, but require separate fields for the time taken, the rear end of my time is passed 2019-10-10 10:10:10in this format, into a format I Fig:
Here Insert Picture Description
but applet dom directly call a function in the interception of the string will not be successful, so the need to do so

Directory Structure

├── pages
│ ├── master-speech
│ │ ├── master-speech.js
│ │ ├── master-speech.wxml
├── utils
│ ├── util.wxs
├── app.js

Core code

<!--master-speech.wxml-->
<wxs module="utils" src="../../utils/util.wxs" />
<block wx:for="{{ oldSpeechList }}"
       wx:key="{{ index }}">
  <!--这一部分可以省略别看
  <view class="before-item"
        data-url="{{ item.post_link }}"
        bindtap="toSpeechDetail">
    <view class="item-left">
      <image class="item-left"
             src="{{ item.featured_images[0].path }}" />
    </view>
    <view class="item-right">
      <view class="right-title">{{ item.title }}</view>
      <view class="right-desc">
        {{ item.excerpt }}
      </view>
      <view class="right-eyes">
        <image class="icon-eyes"
              src="https://assets.dxycdn.com/gitrepo/gsk-tooth/images/index/[email protected]" />
        <view class="eyes-num">{{ item.goods_integral }}</view>
        这一部分可以省略别看-->
        <!--重点在这里-->
        <view class="eyes-time">{{ utils.handleTime(item.updated_at) }}</view>
      </view>
    </view>
  </view>
</block>
// util.wxs
var utils = {
  handleTime: function (data, num=10) {
    return data.slice(0, num)
  }
}
module.exports = {
  handleTime: utils.handleTime
}
Published 165 original articles · won praise 59 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_43972437/article/details/103497845