微信小程序宠物论坛5

微信小程序宠物论坛5

搜索模块

对帖子的标题进行模糊查询
界面如图
在这里插入图片描述

JS部分

// 初始化数据化
const db = wx.cloud.database({});
const cont = db.collection('post');

Page({
  data:{
   post:[],
   title:'',
  },
  formSubmit: function (e) {
    this.setData({
      title1: e.detail.value.find
    })
  },
  // 查询按钮
  find(e) {
    const title1 = this.data.title1
    console.log(title1)
    db.collection("post").where({	 	//collectionName 表示欲模糊查询数据所在collection的名
      title: db.RegExp({
        regexp: title1,
        options: 'i'
      })


    }).get({
      success: res=>{
        console.log(res.data)
        this.setData({
          post: res.data
        })
        
        const post = this.data.post
        console.log(post.length)
        if (post.length == "0") {
          wx.showModal({
            title: '查询结果',
            content: '无相关结果',
            success(res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        } else {
         
        }

      },
    })

  },
 
})

WXML部分

  <view class="content">
    <form  bindsubmit="formSubmit">
      <view class="search">
         <input class="input" type="text" name="find" placeholder="帖子名称" form-type="submit"/> 
         <button class='find' form-type="submit" size="mini" bindtap="find">搜索</button>  
      </view>
    </form>  
 </view> 


<view class="main" wx:for="{{post}}" wx:key="post">
<!-- 帖子ID显示 -->
<navigator url="../detail/detail?id={{item._id}}" open-type="navigate" >
<!-- 标题显示 -->
  <view class="title">{{item.title}}</view>
  <view class="pic">
  <!-- 显示第一张图片 -->
  <image style="width:30%;height:69px;" src="{{item.images[0]}}"/>
  <!-- 头像,发帖人昵称,时间  -->
  <view class="userinfo" style="flex-direction:row">
    <image class="userinfo-avatar" src="{{item.heads}}" background-size="cover"></image>
    <text decode="{{true}}" class="userinfo-nickname">&nbsp;&nbsp;{{item.nickname}}</text>
    <text decode="{{true}}" class="userinfo-time">&nbsp;&nbsp;&nbsp;&nbsp;{{item.time}}</text> 
  </view>
</view>
<view class="line"></view>
</navigator>
</view>

WXSS部分

.content{
  padding-left: 4%;
  padding-right: 4%;
  background-color:rgb(0, 255, 200);
}
.input{
  position:relative;
  top:25rpx;
  height:25px;
  margin-right: 200rpx;  
  border:1px solid #130505;
}
.find{
  margin: 10rpx 10rpx 10rpx 10rpx;  
  z-index: 2;
  border:1px solid #130505;
  position:relative;
  left:500rpx;
  bottom:60rpx
}

.title{
  font-weight: bold;
}
.desc{
font-size:70%;
}

.userinfo-avatar {
  width: 30rpx;
  height: 30rpx;
  border-radius: 50%;
}

.userinfo-nickname {
  font-weight:bold;
  font-size:75%;
  color: black;
  margin-bottom:30px;
}
.userinfo-time{
 font-size:65%;
 padding-bottom:40px
}

.line {
  border: 1px solid #ccc;
  opacity: 0.2;
}

.main{
  padding-left: 4%;
  padding-right: 4%
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值