您当前的位置: 首页 >  搜索

ITKEY_

暂无认证

  • 0浏览

    0关注

    732博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

2020ReactNative本地快速搜索+Ant Design

ITKEY_ 发布时间:2020-09-07 06:48:21 ,浏览量:0

知识点GET
  1. Ant design组件安装
  2. 搜索栏SearchBar
  3. 宫格Grid的使用
  4. Hook简介
涉及的网址

1.ant design rn 官网https://rn.mobile.ant.design/components/grid-cn/

2.Hook 简介 https://react.docschina.org/docs/hooks-intro.html

创建项目并安装ant design组件

可以参考我之前写的文章

https://blog.csdn.net/lxyoucan/article/details/108334465

所需数据
[
    {
        icon: ,
        text: 'a迎新页面',
    },
    {
        icon: ,
        text: 'a学生迎新',
    },
    {
        icon: ,
        text: 'a管理后台',
    },
    {
        icon: ,
        text: 'a我的快递',
    },
    {
        icon: ,
        text: 'a医疗健康',
    },
    {
        icon: ,
        text: 'a记账本',
    },
    {
        icon: ,
        text: 'a发票管家',
    },
    {
        icon: ,
        text: 'a车主服务',
    },
    {
        icon: ,
        text: 'a交通出行',
    },
    {
        icon: ,
        text: 'a体育服务',
    },
    {
        icon: ,
        text: 'a安全备忘',
    },
    {
        icon: ,
        text: 'a健康码',
        url: 'http://www.hao123.com',
    },
    {
        icon: ,
        text: 'b迎新页面',
    },
    {
        icon: ,
        text: 'b学生迎新',
    },
    {
        icon: ,
        text: 'b管理后台',
    },
    {
        icon: ,
        text: 'b我的快递',
    },
    {
        icon: ,
        text: 'b医疗健康',
    },
    {
        icon: ,
        text: 'b记账本',
    },
    {
        icon: ,
        text: 'b发票管家',
    },
    {
        icon: ,
        text: 'b车主服务',
    },
    {
        icon: ,
        text: 'b交通出行',
    },
    {
        icon: ,
        text: 'b体育服务',
    },
    {
        icon: ,
        text: 'b安全备忘',
    },
    {
        icon: ,
        text: 'b健康码',
        url: 'http://www.hao123.com',
    },{
        icon: ,
        text: '1迎新页面',
    },
    {
        icon: ,
        text: '1学生迎新',
    },
    {
        icon: ,
        text: '1管理后台',
    },
    {
        icon: ,
        text: '1我的快递',
    },
    {
        icon: ,
        text: '2医疗健康',
    },
    {
        icon: ,
        text: '2记账本',
    },
    {
        icon: ,
        text: '2发票管家',
    },
    {
        icon: ,
        text: '2车主服务',
    },
    {
        icon: ,
        text: '2交通出行',
    },
    {
        icon: ,
        text: '2体育服务',
    },
    {
        icon: ,
        text: '2安全备忘',
    },
    {
        icon: ,
        text: '2健康码',
        url: 'http://www.hao123.com',
    },
]

完整代码

/* eslint-disable prettier/prettier */
import React,{useState,useEffect} from 'react';
import {ScrollView, Text, View, Alert, SafeAreaView, StyleSheet} from 'react-native';
import {Grid, Icon, SearchBar} from '@ant-design/react-native';

const data1 = [
    {
        icon: ,
        text: 'a迎新页面',
    },
    {
        icon: ,
        text: 'a学生迎新',
    },
    {
        icon: ,
        text: 'a管理后台',
    },
    {
        icon: ,
        text: 'a我的快递',
    },
    {
        icon: ,
        text: 'a医疗健康',
    },
    {
        icon: ,
        text: 'a记账本',
    },
    {
        icon: ,
        text: 'a发票管家',
    },
    {
        icon: ,
        text: 'a车主服务',
    },
    {
        icon: ,
        text: 'a交通出行',
    },
    {
        icon: ,
        text: 'a体育服务',
    },
    {
        icon: ,
        text: 'a安全备忘',
    },
    {
        icon: ,
        text: 'a健康码',
        url: 'http://www.hao123.com',
    },
    {
        icon: ,
        text: 'b迎新页面',
    },
    {
        icon: ,
        text: 'b学生迎新',
    },
    {
        icon: ,
        text: 'b管理后台',
    },
    {
        icon: ,
        text: 'b我的快递',
    },
    {
        icon: ,
        text: 'b医疗健康',
    },
    {
        icon: ,
        text: 'b记账本',
    },
    {
        icon: ,
        text: 'b发票管家',
    },
    {
        icon: ,
        text: 'b车主服务',
    },
    {
        icon: ,
        text: 'b交通出行',
    },
    {
        icon: ,
        text: 'b体育服务',
    },
    {
        icon: ,
        text: 'b安全备忘',
    },
    {
        icon: ,
        text: 'b健康码',
        url: 'http://www.hao123.com',
    }, {
        icon: ,
        text: '1迎新页面',
    },
    {
        icon: ,
        text: '1学生迎新',
    },
    {
        icon: ,
        text: '1管理后台',
    },
    {
        icon: ,
        text: '1我的快递',
    },
    {
        icon: ,
        text: '2医疗健康',
    },
    {
        icon: ,
        text: '2记账本',
    },
    {
        icon: ,
        text: '2发票管家',
    },
    {
        icon: ,
        text: '2车主服务',
    },
    {
        icon: ,
        text: '2交通出行',
    },
    {
        icon: ,
        text: '2体育服务',
    },
    {
        icon: ,
        text: '2安全备忘',
    },
    {
        icon: ,
        text: '2健康码',
        url: 'http://www.hao123.com',
    },
];

const AntSearchDemo = () => {
    const [keyword,setKeyword] = useState('健康');
    const [data,setData] = useState(data1);

    useEffect(() => {
        console.log('keyword:'+keyword);
        let newData = [];
        data1.map((item) => {
                if (item.text.indexOf(keyword) >= 0) {
                    newData.push(item);
                }
            },
        );
        setData(newData);
    },[keyword]);

    const onChange = value => {
        setKeyword(value);
    };

    const clear = () => {
        setKeyword('');
    };
    return (
        
            
                 Alert.alert(value)}
                    showCancelButton
                />
                关键字:{keyword}
                 alert(index)}
                />
            
        
    );
};

export default AntSearchDemo;

const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
});

视频教程

https://www.bilibili.com/video/bv1Zt4y1i7rx

 

关注
打赏
1665243900
查看更多评论
立即登录/注册

微信扫码登录

0.0438s