中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

百容千域可以免費做網(wǎng)站嗎上海廣告公司

百容千域可以免費做網(wǎng)站嗎,上海廣告公司,上海那家公司做響應(yīng)式網(wǎng)站建設(shè),怎么用家里的電腦做網(wǎng)站服務(wù)器1、效果 是你要的效果,咱們繼續(xù)往下看,搜索面板實現(xiàn)省市區(qū)下拉,原本有antd的Cascader組件,但是級聯(lián)組件必須選到子節(jié)點,不能只選省,滿足不了頁面的需求 2、環(huán)境準備 1、react18 2、antd 4 3、功能實現(xiàn) …

?1、效果

是你要的效果,咱們繼續(xù)往下看,搜索面板實現(xiàn)省市區(qū)下拉,原本有antd的Cascader組件,但是級聯(lián)組件必須選到子節(jié)點,不能只選省,滿足不了頁面的需求

2、環(huán)境準備

1、react18

2、antd 4+

3、功能實現(xiàn)

原理:封裝一個受控組件,該組件就是兩select基本組件

1、首先,導入需要的組件:

import { Select, Space, Tag } from 'antd';

?2、定義2個狀態(tài)變量來存儲選中省和市的下拉枚舉

  const [firstOptions, setFirstOptions] = useState<any>([]);const [secondOptions, setSecondOptions] = useState<any>([]);

?3、組件可接收的props子屬性 如下:

  • ?options: 省市級聯(lián)數(shù)據(jù)
  • ?value: 已選中的值
  • ?width:slect框的寬度
  • ?firstPlaceholder 第一個select框的placeholder
  • secondPlaceholder第二個select框的placeholder
  • ?onChange: 選中的值發(fā)生變化時回調(diào)

?4、創(chuàng)建handleFirstChange函數(shù)來處理第一個select框的change事件,更新第二個select框的下拉項和值

  // 第一個select生變化const handleFirstChange = (data: any) => {if (!isEmpty(data) && data.value) {let insertIndex = (options || []).findIndex((item: any) => {return item?.value === data?.value;});setSecondOptions(options?.[insertIndex]?.children || []);onChange({ first: [data] });} else {setSecondOptions([]);onChange(null);}};

?5、創(chuàng)建onSecondChange?函數(shù)來處理第二個select框的change事件,將選中的值回傳給父組件

  // 第二個select發(fā)生變化const onSecondChange = (data: any) => {if (!isEmpty(value) && value.first) {if (!isEmpty(data)) {onChange({...value,second: mode === 'multiple' ? (data || []).filter((item: any) => !isNil(item?.label)) : [data],});} else {onChange({ first: value.first, second: null });}} else {onChange(null);}};

?6、最后,使用2個select組件渲染,并將選中狀態(tài)和change事件綁定到對應(yīng)的屬性上:

return (<><Space wrap={false} direction="horizontal" size={12}><SelectdefaultValue={firstOptions[0]}style={{ width: width }}onChange={handleFirstChange}placeholder={firstPlaceholder || '請選擇'}value={value?.first}options={firstOptions}labelInValueallowClear/><Selectstyle={{ width: width }}value={value?.second || []}onChange={onSecondChange}placeholder={secondPlaceholder || '請選擇'}options={secondOptions}{...mode === "multiple" ? { mode: "multiple", maxTagCount: 'responsive', tagRender: tagRender } : {}}labelInValueallowClear/></Space></>
)

?7、完整代碼如下:

import { Select, Space, Tag } from 'antd';
import clsx from 'clsx';
import { isEmpty, isNil } from 'lodash';
import { useEffect, useState } from 'react';
import './index.less';const MultipleCascaderSelect = (props: any) => {const {options,value,onChange,width = 160,firstPlaceholder,secondPlaceholder,mode = 'multiple'} = props;const [firstOptions, setFirstOptions] = useState<any>([]);const [secondOptions, setSecondOptions] = useState<any>();useEffect(() => {setFirstOptions(options || []);if (Array.isArray(value?.first) && value.first.length) {let findIndex = (options || []).findIndex((item: any) => {return item.value === value.first?.[0].value;});setSecondOptions(options[findIndex]?.children || []);} else {setSecondOptions([]);}}, [options, value]);// 第一個select生變化const handleFirstChange = (data: any) => {if (!isEmpty(data) && data.value) {let insertIndex = (options || []).findIndex((item: any) => {return item?.value === data?.value;});setSecondOptions(options?.[insertIndex]?.children || []);onChange({ first: [data] });} else {setSecondOptions([]);onChange(null);}};// 第二個select發(fā)生變化const onSecondChange = (data: any) => {if (!isEmpty(value) && value.first) {if (!isEmpty(data)) {onChange({...value,second: mode === 'multiple' ? (data || []).filter((item: any) => !isNil(item?.label)) : [data],});} else {onChange({ first: value.first, second: null });}} else {onChange(null);}};const tagRender = ({ label, closable, onClose }: any) => {const isLongTag = `${label}`.length > 4;return (<Tagcolor={label.props?.color}closable={closable}onClose={onClose}className={clsx(['text-sky-400 bg-sky-400/10 text-sm font-normal leading-5',// 'border border-solid border-sky-400/50','max-w-[110px] border-none',// 'whitespace-nowrap text-ellipsis overflow-hidden'])}><span>{isLongTag ? `${label.slice(0, 4)}...` : label}</span>{/* {isLongTag ? (<Tooltiptitle={label}key={label}rootClassName={clsx('toolTipCard')}placement="top"><span>{label.slice(0, 4)}...</span></Tooltip>) : (<span>{label}</span>)} */}</Tag>);};return (<><Space wrap={false} direction="horizontal" size={12}><SelectdefaultValue={firstOptions[0]}style={{ width: width }}onChange={handleFirstChange}placeholder={firstPlaceholder || '請選擇'}value={value?.first}options={firstOptions}labelInValueallowClear/><Selectstyle={{ width: width }}value={value?.second || []}onChange={onSecondChange}placeholder={secondPlaceholder || '請選擇'}options={secondOptions}{...mode === "multiple" ? { mode: "multiple", maxTagCount: 'responsive', tagRender: tagRender } : {}}labelInValueallowClear/></Space></>);
};export default MultipleCascaderSelect;

組件調(diào)用

 <MultipleCascaderSelectwidth={162}options={enumData|| []}firstPlaceholder="請選擇"secondPlaceholder="請選擇"/>

http://www.risenshineclean.com/news/27459.html

相關(guān)文章:

  • 機械門戶網(wǎng)站建設(shè)特點市場營銷推廣策劃
  • 百度收錄網(wǎng)站怎么更改關(guān)鍵詞長沙網(wǎng)站優(yōu)化指導
  • 有什么做任務(wù)的網(wǎng)站嗎網(wǎng)絡(luò)營銷有哪些模式
  • 企業(yè)汽車網(wǎng)站建設(shè)關(guān)鍵詞優(yōu)化難度查詢
  • 韓國女足還能出線嗎愛站seo綜合查詢
  • 做網(wǎng)站的公司叫什么名字國際新聞最新消息戰(zhàn)爭
  • 專業(yè)網(wǎng)站開發(fā)公司免費發(fā)布推廣的平臺有哪些
  • 企業(yè)網(wǎng)站 .net正規(guī)考證培訓機構(gòu)
  • 開發(fā)公司總工崗位職責網(wǎng)站優(yōu)化策略分析
  • 無錫微網(wǎng)站開發(fā)方象科技服務(wù)案例
  • 作品集用什么網(wǎng)站做模板建站難嗎
  • 網(wǎng)站建設(shè)需求怎么寫河北百度推廣客服電話
  • 可以注冊郵箱的網(wǎng)站今天微博熱搜前十名
  • 網(wǎng)站開發(fā)語言怎么看中國國際新聞
  • 網(wǎng)頁版微信二維碼怎么生成seo網(wǎng)站關(guān)鍵詞優(yōu)化方法
  • 網(wǎng)站的注冊頁面怎么做黃頁88網(wǎng)
  • 國內(nèi)外優(yōu)秀設(shè)計網(wǎng)站營銷網(wǎng)站搭建
  • 網(wǎng)站開發(fā)怎么做平板電視seo優(yōu)化關(guān)鍵詞
  • 網(wǎng)站權(quán)限分配代碼知乎小說推廣對接平臺
  • 個人網(wǎng)站備案要求重慶seo全面優(yōu)化
  • 網(wǎng)站建設(shè)-縱橫網(wǎng)絡(luò)鄭州seo優(yōu)化外包公司
  • 網(wǎng)站推廣服務(wù)具體內(nèi)容包括哪些0元做游戲代理
  • 工程造價定額在哪查網(wǎng)站推廣優(yōu)化設(shè)計方案
  • 織夢網(wǎng)站被做跳轉(zhuǎn)企業(yè)宣傳軟文范例
  • 免費網(wǎng)站注冊com重慶seo排名
  • 利用access做網(wǎng)站電腦培訓網(wǎng)上免費課程
  • 門戶網(wǎng)站制作石家莊網(wǎng)絡(luò)關(guān)鍵詞排名
  • 百度網(wǎng)站站長工具個人博客登錄首頁
  • 織夢手機網(wǎng)站圖片谷歌應(yīng)用商店app下載
  • 定制網(wǎng)站開發(fā)成本估算表南寧整合推廣公司