当前位置:网站首页>[pit avoidance refers to "difficult"] antd cascader implements new customized functions

[pit avoidance refers to "difficult"] antd cascader implements new customized functions

2022-06-25 13:16:00 Coconut brine Engineer

The renderings are as follows : You can customize how to add data in a certain layer
 Insert picture description here

Code implementation

Yes Cascader Medium options Do the processing

		 <Cascader
            allowClear
            expandTrigger="hover"
            options={
    customerOption}
          />
const customerOption = handlecustomerOption(showoptions);
const handlecustomerOption=(opt: any) =>{
    
  if (opt && opt.length) {
    
    opt.forEach((item: any) => {
    
      if (item.children && item.children.length) {
    
        item.fieldNames = item.value;
        item.children.forEach((child: any) => {
    
          let tempObj = {
    };
          tempObj = {
    
            label: (
              <span>
                <span title={
    child.value} className="layoutTitle">{
    child.label}</span>
                {
     child.label ?'':
              <Button
	              type="link"
	              icon={
    <PlusOutlined />}
	              style={
    {
     marginTop: -5 }}>
               newly added 
            </Button>}
              </span>
            ),
            value: child.value,
            fieldNames: child.value,
          };
          Object.assign(child, tempObj);
        });
      }
    });
  }

option initialization JSON The format is as follows :

  const showoptions = [
    {
    
      value: 'zhejiang',
      label: 'Zhejiang',
      children: [
        {
    
          value: '',
          label: '',
        },
        {
    
          value: 'hangzhou',
          label: 'Hangzhou',
          children: [
            {
    
              value: 'xihu',
              label: 'West Lake',
            },
          ],
        },
      ],
    },
    {
    
      value: 'jiangsu',
      label: 'Jiangsu',
      children: [
        {
    
          value: 'nanjing',
          label: 'Nanjing',
        },
      ],
    },
  ];

{value: '',label: '',} It is equivalent to occupying the top first position in the drop-down data , adopt handlecustomerOption() take label replaced button, So as to realize the new functions .

原网站

版权声明
本文为[Coconut brine Engineer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200526312914.html