• 小程序追加数据的实现方法


    index.wxml

    <block wx:for="{{demoData}}" wx:for-item="item" wx:for-index="idx">
      <view class="demos">
        <view><text>测试的时间:</text><text>{{item.demoTime}}</text></view>
        <view><text>测试的内容:</text><text>{{item.demoCon}}</text></view>
      </view>
    </block>
    
    <view class="btn" catchtap="anniu">追加的按钮</view>

    index.js

    Page({
      data: {
        demoData: [
          {
            demoTime: "2017-2-6",
            demoCon: '我是测试代码001'
          },
          {
            demoTime: "2017-8-6",
            demoCon: '我是测试代码002'
          }
        ]
      },
      onLoad: function () {
        this.setData({
          nowDate: util.formatTime(new Date())
        });
      },
      anniu:function(){
        var zhuijia = {demoTime: "2017-7-7", demoCon: '我是追加的测试代码'};
        this.data.demoData.unshift(zhuijia);
        this.setData({
          demoData: this.data.demoData
        });
      }
    })

    index.wxss

    .demos{
       100%;
      height: 100px;
      line-height: 50px;
      background-color: #188eee;
      color: #fff;
      margin: 10px 0px;
    }
    .btn{
      height: 50px;
       80%;
      margin-left: 10%;
      line-height: 50px;
      background-color:orangered;
      color: #fff;
      text-align: center;
    }

  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    codevs 2977 二叉堆练习1x
    codevs 2010 求后序遍历x
    二叉树的序遍历x(内含结构体与非结构体版x)
    医院设置x
    求后序遍历x
    [LightOJ1017]Brush (III)(dp)
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/7146715.html
Copyright © 2020-2023  润新知