自動補全的 select antd react

自動補全的 select antd react
文檔:自動補全的 select antd react.note
鏈接:http://note.youdao.com/noteshare?id=f5e4a93d2b9d6be8e459edd4eb86323b&sub=19796E9BC04D4ABD9ACE325FDFF59B0E
添加鏈接描述


import React, { useState, useRef } from 'react';
import { AutoComplete, Button, Input } from 'antd';
import axios from 'axios';
import { useNavigate } from 'react-router-dom';
import TimeUtil from '@/utils/TimeUtil';interface AutoCompleteSearchBoxProps {// history: any; // 這里的類型可以根據你的實際需求進行調整// data: any; // 這里的類型可以根據你的實際需求進行調整value: any;onChange: any;// onSelectChange 
}interface SearchResult {label: string;
}
// { value=null, onChange=(val:any)=>{} }
// D:\proj\brain\admin-antd-react\src\components\AutoCompleteSearchInput
// JumpSearchBox
// JumpSearchBox
const AutoCompleteSearchInput: React.FC<AutoCompleteSearchBoxProps> = (props) => {const [searchResults, setSearchResults] = useState<SearchResult[]>([]);const inputRef = useRef<Input>(null);const navigate = useNavigate();const [searchVal, setSearchVal] = useState<string | null>(null);const handleButtonClick = () => {console.log("handleButtonClick")// console.log("autoCompleteRef.current")console.log("inputRef.current")console.log(inputRef.current)console.log("searchVal")console.log(searchVal)// console.log(autoCompleteRef.current)// if (autoCompleteRef.current) {//   const searchData = autoCompleteRef.current.getData(); // 獲取AutoCompleteSearchInput組件的數據//   console.log(searchData);// }};// "前一周",const options = ["前三天",  "前一個月", "前一年"];function getSearchLabels(options) {let list = []for (let option of options) {list.push({keywords: option,label: option},)}// console.log("list")// console.log(list)return list}// ts 獲取 前一周的 時間戳// <TimeUtil className="wee"> </TimeUtil>let SearchLabels = [{keywords: "dadad",label: "dadad"},{label: "ada"},{label: "前一年",// timestamp: TimeUtil.yesterdayMillis(-3)},{keywords: "week,前一周,周,zhou,1",label: "前一周",timestamp: TimeUtil.weekAddTimeStamp(-1)},...getSearchLabels(options)];// TimeUtil.weekAddTimeStamp(-3)function strIsLike(str: string, str2: string) {return str.includes(str2) || str2.includes(str)}function findLikeStrs(str, SearchLabels) {let resList = []for (let obj of SearchLabels) {// obj.labelif (// strIsLike(str, obj.label)strIsLike(str, obj.keywords||obj.label)) {resList.push(obj)}}return resList}const handleSearch = (value: string) => {if (!value) {setSearchResults(SearchLabels);return}props?.onChange(value)// 發送遠程搜索請求axios.get(`https://api.example.com/search?q=${value}`).then((response) => {const searchResults = response.data.results;setSearchResults(searchResults);}).catch((error) => {console.error('Error fetching search results:', error);// const searchResults: SearchResult[] = SearchLabels// setSearchResults(searchResults);//  setSearchResults(SearchLabels);setSearchResults(findLikeStrs(value, SearchLabels));});// if (value) {// } else {//   setSearchResults([]);// }};const handleSelect = (value: string) => {setSearchVal(value)props.onChange(value)console.log("inputRef.current");console.log(inputRef.current);inputRef.current?.focus();// console.log(    "inputRef.current?.input.setValue");// console.log(    inputRef.current?.input.setValue);// inputRef.current?.input.setValue(value);let inputItem = inputRef.current?.inputinputItem.value = valueconst path = `/details/${value}`;// navigate(path);console.log("props");console.log(props);console.log("props.history");console.log(props.history);};return (<div><AutoCompletestyle={{ width: 200 }}options={searchResults.map((result) => ({value: result.label,label: result.label,}))}onSearch={handleSearch}onSelect={handleSelect}><Inputref={inputRef}placeholder="請輸入關鍵字"/></AutoComplete>{/* <Button type="primary" onClick={handleButtonClick} >AutoCompleteSearchInputButton</Button> */}</div>);
};export default AutoCompleteSearchInput;

import AutoCompleteSearchInput from '@/components/AutoCompleteSearchInput';<div>AutoCompleteSearchInput<AutoCompleteSearchInput onChange={onSelectChange} ref={autoCompleteRef} history={undefined} ></AutoCompleteSearchInput>{/* 點擊按鈕 獲取 AutoCompleteSearchInput的 數據  */}<Button type="primary" onClick={handleButtonClick} >AutoCompleteSearchInputButton</Button></div>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/208444.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/208444.shtml
英文地址,請注明出處:http://en.pswp.cn/news/208444.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【1day】泛微e-office OA系統xml.php 文件 SORT_ID 參數 SQL 注入漏洞學習

注:該文章來自作者日常學習筆記,請勿利用文章內的相關技術從事非法測試,如因此產生的一切不良后果與作者無關。 目錄 一、漏洞描述 二、影響版本 三、資產測繪 四、漏洞復現

理解傳統模式與互聯網時代 消費行為模型 AIDMA , AISAS , SICAS

1 AIDMA與AISAS 消費行為模型&#xff0c;以及所誕生的IT崗位 1.1 傳統市場營銷消費行為模型 AIDMA模型&#xff1a;Attention&#xff08;吸引&#xff09;&#xff0c;Interest &#xff08;興趣&#xff09;&#xff0c;Desire&#xff08;欲望&#xff09; &#xff0c;Me…

LeetCode 76. 最小覆蓋子串 滑動窗口框架

雙指針的特殊應用&#xff1a;滑動窗口 代碼 題目鏈接&#xff1a;https://leetcode.cn/problems/minimum-window-substring/description/ 不說廢話&#xff0c;直接貼代碼&#xff1a; static string minWindow(string s, string t) {// need記錄需要匹配的字符串t中每個字…

? Mac IDEA使用并運行項目

? IDEA導入項目并運行 Mac IDEA使用 (1) 倉庫導入 通過獲取giett倉庫包的url&#xff0c;在idea中導入項目 在gitee里獲取項目的ur打開idea&#xff0c;點擊 File->new->Project from Version Control (2) 創建數據庫ry并導入數據腳本 &#xff08;3&#xff09;修改配…

華為配置Smart Link主備備份示例

定義 Smart Link&#xff0c;又叫做備份鏈路。一個Smart Link由兩個接口組成&#xff0c;其中一個接口作為另一個的備份。Smart Link常用于雙上行組網&#xff0c;提供可靠高效的備份和快速的切換機制。 Monitor Link是一種接口聯動方案&#xff0c;它通過監控設備的上行接口…

npm私有源構建項目下載依賴報錯

Jenkins構建項目報錯&#xff0c;依賴找不到 Error: Couldnt find any versions for "babel/helper-module-imports" that matches "^7.22.15"at MessageError.ExtendableBuiltin (/data1/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/…

log4j(日志的配置)

日志一般配置在resources的config下面的&#xff0c;并且Util當中的initLogRecord中的initLog&#xff08;&#xff09;方法就是加載這個log4j.properties的. 首先先看log4j.properties的配置文件 log4j.rootLoggerdebug, stdout, Rlog4j.appender.stdoutorg.apache.log4j.Co…

高性能和多級高可用,云原生數據庫 GaiaDB 架構設計解析

1 云原生數據庫和 GaiaDB 目前&#xff0c;云原生數據庫已經被各行各業大規模投入到實際生產中&#xff0c;最終的目標都是「單機 分布式一體化」。但在演進路線上&#xff0c;當前主要有兩個略有不同的路徑。 一種是各大公有云廠商選擇的優先保證上云兼容性的路線。它基于存…

考研真題數據結構

【2021年山西大學真題】將二叉樹中所有非終端結點的左右子樹交換位置&#xff0c;可以得到原二叉樹的 鏡像二叉樹&#xff0c;如圖。假設二叉樹的存儲形式為&#xff08;lchild&#xff0c;data&#xff0c;rchild&#xff09;&#xff0c;給出求鏡像二叉樹的算法: &#xff0…

Sql Server Management Studio連接Mysql

目標 已知mysql連接參數&#xff08;地址和用戶&#xff09;&#xff0c;期望通過Microsoft Sql Server Management Studio &#xff08;以下簡稱MSSSMS&#xff09;連接Mysql&#xff0c;在MSSSMS中直接查詢或修改Mysql中的數據。 下載MySql Connector/ODBC并安裝&#xff0c…

使用poi-tl填充word模板,并轉化為pdf輸出

后端 依賴 <dependency><groupId>com.deepoove</groupId><artifactId>poi-tl</artifactId><version>1.12.0</version> </dependency>Word版本 Word版本填充代碼 // 培訓詳情HashMap<String, Object> textMap new Ha…

maven環境搭建

maven歷史版本下載&#xff1a;https://archive.apache.org/dist/maven/ 新建系統變量編輯Path&#xff0c;添加bin目錄mvn -v測試查看版本號conf目錄下新建repository文件夾&#xff0c;作為本地倉庫 settings.xml <?xml version"1.0" encoding"UTF-8&…

2312d,d語言來綁定C++和rust

原文 各編譯語言相同概念 1,按可重用函數拆分代碼. 2,由源碼中的函數名生成的串來標識函數.如,g為void foo()生成_Z3foov的標識.此串總是是可重現的;如,Linux上的Clang和GCC都遵循ItaniumCABI約定來裝飾函數名. 3,在內存中的特定位置存儲該函數的所有參數,然后用調用或等效指…

gitee配置

注冊配置gitee Gitee官網 進入官網之后&#xff0c;有賬號直接登錄&#xff0c;沒有賬號注冊一個新的賬號 下載安裝git客戶端 官網地址 下載完成&#xff0c;一路直接點擊安裝直接安裝成功 檢查是否安裝成功 鼠標留在桌面–>右擊–>出現Git GUI Here/Git Bash Her…

windows系統nodeJs報錯node-sass npm ERR! command failed

報錯信息 npm WARN deprecated request2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm WARN deprecated tar2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asa…

國科大通信原理復習

CH4-信源的數字化 26. 信源編碼的基本方法和分類 27. 無失真編碼和有失真編碼的區別 無失真編碼能夠完全一模一樣的恢復到原信號。 有失真編碼則不行。 28. 信息量和熵的定義 29. 離散信源的最大熵定理 n表示所有符號的種類&#xff0c;比如對于二進制碼字&#xff0c;Rbit對…

云計算ACP認證考試題庫0-100

0001.單選題:阿里云的云盾會檢查通過公共互聯網登錄云服務器ECS的來源IP,登錄方式包括SSH和遠程桌面,當來自某個IP的登錄請求出現多次密碼錯誤的情況時,會發出”ECS遭遇密碼暴力破解”的報警,當收到這個報警后,最安全的處理方法應該是。 A.通知自己業務平臺的所有用戶立即修改…

基于支持向量機SVM的新鮮度等級預測,基于自適應粒子群優化長短期神經網絡的新鮮度等級預測

目錄 背影 支持向量機SVM的詳細原理 SVM的定義 SVM理論 粒子群算法原理 SVM應用實例,基于支持向量機SVM的新鮮度等級預測,基于自適應粒子群優化長短期神經網絡的新鮮度等級預測 代碼 結果分析 展望 完整代碼:基于支持向量機SVM的新鮮度等級預測,基于自適應粒子群優化長短期…

SpringBoot+線程池實現高頻調用http接口并多線程解析json數據

場景 SpringbootFastJson實現解析第三方http接口json數據為實體類(時間格式化轉換、字段包含中文)&#xff1a; SpringbootFastJson實現解析第三方http接口json數據為實體類(時間格式化轉換、字段包含中文)-CSDN博客 Java中ExecutorService線程池的使用(Runnable和Callable多…

MindOpt APL:一款適合優化問題數學建模的編程語言

什么是建模語言 建模語言是一種描述信息或模型的編程語言&#xff0c;在運籌優化領域&#xff0c;一般是指代數建模語言。 比如要寫一個線性規劃問題的建模和求解&#xff0c;可以采用C、Python、Java等通用編程語言來實現計算機編程&#xff08;碼代碼&#xff09;&#xff0…