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

三层网络架构长沙seo推广公司

三层网络架构,长沙seo推广公司,品牌注册公司,湖南企业竞价优化服务概要 在实际开发中,我们常常碰到,一个页面根据条件不同,其展示的表单项需要动态改变位置;但是又不想写重复代码;可以试一下以下方法; 效果 使用的技术 HtmlReact,useMemoES6的扩展运算 代码 import Re…

概要

在实际开发中,我们常常碰到,一个页面根据条件不同,其展示的表单项需要动态改变位置;但是又不想写重复代码;可以试一下以下方法;

效果

在这里插入图片描述

使用的技术

  • Html
  • React,useMemo
  • ES6的扩展运算

代码

import React, { Fragment, useMemo } from 'react'export default function DefaultPage() {const testComponent = () => {return <div key={"nationality"}>国籍:<select><option value="1">中国</option><option value="2">美国</option><option value="3">韩国</option></select></div>}const fields = useMemo(() => {return {data: [{id: 1,name: 'name',label: "姓名",type: 'text'},{id: 2,name: 'age',label: "年龄",type: 'text'},{id: 3,name: 'address',label: "地址",type: 'text'}],other: [{id: 4,name: 'email',label: "邮箱",otherComponent: <div>邮箱:<input type='email' /></div>},{id: 6,name: 'phone',label: "电话",otherComponent: <div>电话:<input type='phone' /></div>},],other2: [{id: 7,name: 'nationality',label: "国籍",otherComponent: testComponent()},]}}, [])const defaultFields = [...fields.data, ...fields.other, ...fields.other2]const appointFields = ["age", "nationality", "name"]const defaultSort = defaultFields.sort((a, b) => a.id - b.id)const appointSortList =()=>{const list = []appointFields.forEach((item) => {const newlist = defaultFields.filter((item2) => item2.name === item)list.push(...newlist)})return  list}const appointSort =  appointSortList()const totalRender = (list) => {return <div>{list?.map((item) => {if (item.otherComponent) {return item.otherComponent} else {return renderForm(item)}})}</div>}const renderForm = (item) => {return <div key={item.id}>{item.label}:<input type={item.type} name={item.name} key={item.id} /></div>}return (<Fragment>默认排序:{totalRender(defaultSort)}<br/>指定排序:---------------{totalRender(appointSort)}</Fragment>)
}

< Fragment >是代替<></>标签,无实际意义。指示提醒这是一大块代码块; useMemo是react中用于缓存计算结果的方法,可以根据依赖,动态刷新缓存值

⚠️testComponent方法要写在useMemo方法前,不然会报错
在这里插入图片描述

http://www.dtcms.com/wzjs/46625.html

相关文章:

  • 音乐分享 wordpress西安官网seo技术
  • 做的比较好的二手交易网站有哪些sem推广竞价托管公司
  • 代理服务器地址是什么意思惠州seo优化服务
  • 广州网站建设建航特大新闻凌晨刚刚发生
  • php装饰公司网站源码网站seo如何优化
  • 微信上的网站怎么做网站如何快速收录
  • 宁波企业网站制作推荐seo 页面
  • 阿里云wordpress更新谷歌优化工具
  • 天地做网站站内营销推广途径
  • 装修怎么做网站自己做网站设计制作
  • photoshop做网站设计营销策略从哪几个方面分析
  • 万网虚拟云空间怎么建设网站seo经理招聘
  • 怎样在网站上做销售微博推广价格表
  • 织梦dedecms医院类网站在线预约挂号插件_utf8seo最新技巧
  • 网站开发有哪些公司301313龙虎榜
  • 福州朝阳房产网站建设本周国内新闻
  • 武汉做网站珠海百度seo
  • PR做视频需要放网站上天津seo排名公司
  • 新光途网站建设网络媒体
  • 永久网站域名注册长沙搜索排名优化公司
  • 有了源码怎么做网站seo技巧优化
  • 深圳建设网站费用明细百度提问登陆入口
  • 营销策略是什么常用seo站长工具
  • 做网站的目的和要求营销推广平台
  • 网站类型大全山东今日热搜
  • 龙岩网站建设品牌运营总监
  • 南京专业做网站的公司有哪些网站怎么做外链
  • 拿word如何做网站免费seo培训
  • 网站开发国际化网站seo视频
  • 重庆黔江做防溺水的网站网站建立具体步骤是