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

泉州网站建设方案外包苏州排名搜索优化

泉州网站建设方案外包,苏州排名搜索优化,qq网页版在线登录,如何在国际上做网站1、效果 是你要的效果#xff0c;咱们继续往下看#xff0c;搜索面板实现省市区下拉#xff0c;原本有antd的Cascader组件#xff0c;但是级联组件必须选到子节点#xff0c;不能只选省#xff0c;满足不了页面的需求 2、环境准备 1、react18 2、antd 4 3、功能实现 … 1、效果 是你要的效果咱们继续往下看搜索面板实现省市区下拉原本有antd的Cascader组件但是级联组件必须选到子节点不能只选省满足不了页面的需求 2、环境准备 1、react18 2、antd 4 3、功能实现 原理封装一个受控组件该组件就是两select基本组件 1、首先导入需要的组件 import { Select, Space, Tag } from antd; 2、定义2个状态变量来存储选中省和市的下拉枚举 const [firstOptions, setFirstOptions] useStateany([]);const [secondOptions, setSecondOptions] useStateany([]); 3、组件可接收的props子属性 如下 options: 省市级联数据 value: 已选中的值 widthslect框的宽度 firstPlaceholder 第一个select框的placeholdersecondPlaceholder第二个select框的placeholder onChange 选中的值发生变化时回调 4、创建handleFirstChange函数来处理第一个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、创建onSecondChange 函数来处理第二个select框的change事件将选中的值回传给父组件 // 第二个select发生变化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组件渲染并将选中状态和change事件绑定到对应的属性上 return (Space wrap{false} directionhorizontal 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] useStateany([]);const [secondOptions, setSecondOptions] useStateany();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发生变化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)}placementtopspan{label.slice(0, 4)}.../span/Tooltip) : (span{label}/span)} */}/Tag);};return (Space wrap{false} directionhorizontal 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;组件调用 MultipleCascaderSelectwidth{162}options{enumData|| []}firstPlaceholder请选择secondPlaceholder请选择/
http://www.zqtcl.cn/news/984853/

相关文章:

  • 大型网站建设一般多少钱wordpress 调用百度前端公众库
  • 个人电脑做网站服务器网站地方网站域名用全拼
  • 我们网站在那里登陆后台系统管理成都app制作开发
  • 可以做问卷调查的网站仙居网站建设
  • 知名网站建设公司电话做一个小程序需要多少钱
  • 外贸找客户有什么网站个人如何做网站
  • 旅游项目网站开发ui界面设计分析
  • 企业建设网站没有服务器代理网页浏览
  • 深圳网站建设新闻网站建设营销的企业
  • 建筑设计网站软件排名工具
  • wordpress theme珠宝最适合seo的网站源码
  • 建设工程规划许可证查询网站畜牧业网站模板
  • 做网站大概要多少钱页面网站缓存如何做
  • 家电网站建设需求分析朔州网络推广
  • 陕西交通建设集团网站体检网络营销中自建网站
  • 做游戏的php网站有哪些微信商城是什么
  • wordpress memcached redux深圳网站优化方法
  • 移动商城 网站建设方法方式韩国导航地图app
  • 企业网站源码是什么瑞安企业做网站
  • 佛山深圳建网站wordpress 段代码
  • 网站备案 强制仿牌网站容易被攻击吗
  • 网站做访问追踪js特效演示网站
  • 建设网站女装名字大全宝宝投票网站怎么做
  • 江苏省建设厅网站首页天津百度网站排名优化
  • 织梦网络设计工作室网站模板镇江市精神文明建设网站
  • 网站管理工具装修公司设计软件有哪些
  • 招标网站的服务费怎么做分录什么网站做玩具的比较多
  • 青海省住房建设厅网站WordPress主题启用出现错误
  • 自己怎么建网站网站的seo 如何优化
  • 博客网站模板下载如何自学美工