当前位置: 首页 > news >正文

微信小程序:仅前端实现对象数组的模糊查询

效果

 

核心代码

//对数组进行过滤,返回数组中每一想满足name值包括变量query的

let result = array.filter(item => {

      return item.name.includes(query);

});

完整代码

wxml

<input type="text" placeholder="请输入名称" placeholder-style="color:black" bindconfirm="search" />
<view class="all"><view class="item_all" wx:for="{{info}}" wx:key="index"><view class='position'><view class="content"><view class="vv_1">序号:{{item.id}}</view><view class="vv_1">名称:{{item.name}}</view><view class="vv_1">年龄:{{item.age}}</view></view></view></view>
</view>

wxss

/* 搜索框 */
input {background-color: rgb(212, 212, 212);padding: 2%;margin-bottom: 5%;
}/* 列表 */
.all {margin-bottom: 20%;
}.item_all {/* border: 1px solid black; */margin-bottom: 3%;display: flex;flex-direction: column;align-items: center;justify-content: center;width: 100%;
}.position {display: flex;flex-direction: column;justify-content: center;width: 95%;border-radius: 10px;background-color: #fff;box-shadow: 2px 2px 2px gainsboro;
}.content {padding: 5%;
}.vv_1 {word-break: break-all;padding: 2px 0;
}

js

Page({data: {//完整数据fixed_info: [{id:1,name:'张三',age:23}, {id:2,name:'李四',age:26}, {id:3,name:'王五',age:24}, {id:4,name:'张晓',age:21}], //展示数据info:[],},//刚进入页面执行的操作onLoad(options) {this.setData({info:this.data.fixed_info})  },//搜索框回车事件search(event) {//始终保持查询的数据是完整的数组数据this.setData({info:this.data.fixed_info})let query = event.detail.value; // 要查询的关键词let array = this.data.info;//设置查询的数组let result = array.filter(item => {return item.name.includes(query);});this.setData({info:result})},
})

http://www.lryc.cn/news/230493.html

相关文章:

  • 【done】剑指offer63:股票的最大利润
  • 桶装水订水小程序app,线上预约订水更便捷
  • 解决进程同步与互斥的Dekker算法与Peterson算法
  • confluence无法打开空间目录
  • python用pychart库,实现将经纬度信息在地图上显示
  • Android Studio的笔记--随机数
  • 《诗经》中28首巅峰之作
  • 十大适合外贸企业邮箱的Gmail替代品推荐
  • 在Python中使用sqlite3进行数据持久化操作
  • file2Udp增量日志转出Udp简介
  • 快速创建1个G的文件 -----window平台
  • LeetCode【33】搜索旋转排序数组
  • 若依系统富文本框上传图片报错!
  • Azure 机器学习:MLOps - 使用 Azure 机器学习进行模型管理、部署和监视
  • CSDN每日一题学习训练——Java版(分数到小数、罗马数字转整数、x 的平方根)
  • 【2021集创赛】 RISC-V杯三等奖:基于E203 处理器的SM4算法硬件加速
  • SUMO道路封闭车辆绕行仿真实验【TraCI】
  • IDEA 无法搜索或者下载插件
  • unity 使用Vuforia扫描实体物体交互
  • IDEA接口调试插件不好找?这款免费用!
  • OpenCV图像坐标系
  • 【Proteus仿真】【Arduino单片机】DHT11温湿度
  • Linux--makefile
  • Anaconda学习备忘
  • uniapp运行到安卓模拟器一直在“同步手机端程序文件完成“界面解决办法
  • leetcode:876. 链表的中间结点
  • 【m98】webrtc vs2017构建带符号的debug库
  • 【读点论文】结构化剪枝
  • JimuReport积木报表 v1.6.5 版本发布—免费报表工具
  • 【开发工具】gitee还不用会?我直接拿捏 >_>