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

做网站毕业答辩会问什么东莞做网站推广

做网站毕业答辩会问什么,东莞做网站推广,wordpress小程序音频插件,打开国外网站很慢前言 JSON 平时大家都会用到,都不陌生,今天就一起来实现一个 JSON 的可视化工具。 大概长成下面的样子: 树展示 相比于现有的一些 JSON 格式化工具,我们今天制作的这个小工具会把 JSON 转为树去表示。其中: 橙色标…

前言

JSON 平时大家都会用到,都不陌生,今天就一起来实现一个 JSON 的可视化工具。

大概长成下面的样子:

image.png

树展示

相比于现有的一些 JSON 格式化工具,我们今天制作的这个小工具会把 JSON 转为树去表示。其中:

  • 橙色标签表示 key
  • 蓝色标签表示 value
  • 绿色标签表示类型: Number String Object Array Null

左边是一个输入框,右边是一个实时反馈的 JSON 可视化区域。下面来看一下大致的实现思路:

  1. 当输入框的值变化时,使用 JSON.parse 解析值,如果是一个合法的 JSON ,则进行下一步处理;如果不是,则把异常显示出来
  2. 递归把 JSON 对象解析成数组树的结构,主要会包含以下几个 key
    • key 唯一标识,后续用做复制路径
    • title JSON 属性节点 key
    • value JSON 属性节点值
    • isArrayProps 是否是数组的节点
    • children 子节点
    • type 值类型
  const handleParse = useCallback(debounce((value) => {if (!value) {return;}try {const res = JSON.parse(value);setJson(res);setError(null);setUpdateKey((key) => key + 1);setSearchValue("");} catch (error) {setJson({});setError(error);}}, 300),[]);useEffect(() => {handleParse(value);}, [value]);

value 是输入框的输入值,当输入值变化时,解析 JSON 。获取到新的 JSON 值后,开始递归处理,组装成树结构:

  const treeData = useMemo(() => {const dfs = (json, parentKey) => {const res = [];const keys = Object.keys(json);for (const index in keys) {const key = keys[index];const value = json[key];res[index] = {key: parentKey ? `['${parentKey}']['${key}']` : `['${key}']`,title: key,value: value ? value.toString() : value,isArrayProps: Array.isArray(json),children:typeof value === "object" && value !== null ? dfs(value, key) : [],type: upperFirst(value === null? "null": Array.isArray(value)? "array": typeof value),};}return res;};try {return dfs(json, "");} catch (error) {console.log("err", error);return [];}}, [json]);

然后用一个树组件把它渲染出来:

<TreeshowIconshowLinetitleRender={renderTitle}key={updateKey}treeData={treeData}defaultExpandAll
/>

其中,我们希望自定义渲染树的每一个节点,所以可以实现一个 titleRender 方法:

  const renderTitle = (node) => {return (<div onClick={() => copy}>{!node.isArrayProps ? <Tag color="orange">{node.title}</Tag> : ""}{node.children.length === 0 && node.value ? (<Tag color="blue">{node.value}</Tag>) : ("")}<Tag color="green">{node.type}</Tag></div>);};

image.png

这样就完成了基础的功能逻辑及渲染

搜索

这里我们拓展一个根据关键词搜索的功能,既可以搜索 key ,也可以搜索 value

用到一个 Search 组件来搜集 keyword

<Input.Searchstyle={{ marginBottom: 8 }}placeholder="Search"onChange={(e) => setSearchValue(e.target.value)}
/>

然后当 keyword 变化的时候,去匹配树节点中的属性值,如果匹配到了,就把对应的值标红。

  const renderTitle = (node) => {const highlight = (strTitle) => {const index = strTitle.indexOf(searchValue);const beforeStr = strTitle.substring(0, index);const afterStr = strTitle.slice(index + searchValue.length);const title =index > -1 ? (<span>{beforeStr}<span style={{ color: "red" }}>{searchValue}</span>{afterStr}</span>) : (<span>{strTitle}</span>);return title;};return (<div onClick={() => copy}>{!node.isArrayProps ? (<Tag color="orange">{highlight(node.title)}</Tag>) : ("")}{node.children.length === 0 && node.value ? (<Tag color="blue">{highlight(node.value)}</Tag>) : ("")}<Tag color="green">{node.type}</Tag></div>);};

最后实现出来的效果就是这样的;

image.png

复制路径

我不知道大伙有过这样类似的需求:改动一个 json 对象某个 key 对应的值。我之前是有过这样的场景,那是在使用 Lottie 做动画的时候。

我需要对描述 Lottie 动画的 json 文件进行一些修改,但往往这种文件层级非常深,如果不借助一些工具,是很难找到对应的值的路径是什么,找不到路径就很难修改了。

那么我们有了这个工具之后,就很轻松可以通过搜索+复制的方式来找到某个值对应的路径。

<Clipboard text={node.key} onCopy={() => message.success("路径已复制")}><div>{!node.isArrayProps ? (<Tag color="orange">{highlight(node.title)}</Tag>) : ("")}{node.children.length === 0 && node.value ? (<Tag color="blue">{highlight(node.value)}</Tag>) : ("")}<Tag color="green">{node.type}</Tag></div>
</Clipboard>

用一个复制组件包裹树节点,点击的时候把节点的 key 属性复制到粘贴板。

image.png

image.png

这样就可以轻松获取到节点所对应的 key 了。

最后

以上就是本文的全部内容,如果你感兴趣的话,点点关注点点赞吧~


文章转载自:
http://credo.wwxg.cn
http://pechora.wwxg.cn
http://childrenese.wwxg.cn
http://topi.wwxg.cn
http://challah.wwxg.cn
http://tammerkoski.wwxg.cn
http://heterocharge.wwxg.cn
http://isopycnosis.wwxg.cn
http://libau.wwxg.cn
http://tatary.wwxg.cn
http://wishfully.wwxg.cn
http://gushing.wwxg.cn
http://recrement.wwxg.cn
http://ethiopia.wwxg.cn
http://limpkin.wwxg.cn
http://braaivleis.wwxg.cn
http://layette.wwxg.cn
http://psychical.wwxg.cn
http://feraghan.wwxg.cn
http://acne.wwxg.cn
http://fujisan.wwxg.cn
http://hardwareman.wwxg.cn
http://unimpeachably.wwxg.cn
http://cervicovaginal.wwxg.cn
http://tuner.wwxg.cn
http://unbolted.wwxg.cn
http://antidiabetic.wwxg.cn
http://pluvious.wwxg.cn
http://sarpedon.wwxg.cn
http://meristem.wwxg.cn
http://helaine.wwxg.cn
http://hellweed.wwxg.cn
http://esterase.wwxg.cn
http://iconology.wwxg.cn
http://regius.wwxg.cn
http://surcingle.wwxg.cn
http://unintelligent.wwxg.cn
http://climber.wwxg.cn
http://rhinoceros.wwxg.cn
http://buskin.wwxg.cn
http://gismo.wwxg.cn
http://fiat.wwxg.cn
http://permutable.wwxg.cn
http://covelline.wwxg.cn
http://demonise.wwxg.cn
http://accusingly.wwxg.cn
http://wimpy.wwxg.cn
http://karlsruhe.wwxg.cn
http://overeducate.wwxg.cn
http://betrothal.wwxg.cn
http://fusillade.wwxg.cn
http://borickite.wwxg.cn
http://erastian.wwxg.cn
http://decorous.wwxg.cn
http://kyoto.wwxg.cn
http://exalted.wwxg.cn
http://jailbait.wwxg.cn
http://eclair.wwxg.cn
http://flaring.wwxg.cn
http://transposon.wwxg.cn
http://idyl.wwxg.cn
http://dubbing.wwxg.cn
http://polemicize.wwxg.cn
http://zi.wwxg.cn
http://lithophagous.wwxg.cn
http://fibroplasia.wwxg.cn
http://touching.wwxg.cn
http://nixie.wwxg.cn
http://fugleman.wwxg.cn
http://asroc.wwxg.cn
http://radwaste.wwxg.cn
http://furnace.wwxg.cn
http://foul.wwxg.cn
http://downlink.wwxg.cn
http://bimotored.wwxg.cn
http://gemini.wwxg.cn
http://tympano.wwxg.cn
http://tapped.wwxg.cn
http://guerilla.wwxg.cn
http://metathoracic.wwxg.cn
http://uv.wwxg.cn
http://macrograph.wwxg.cn
http://hedonic.wwxg.cn
http://telekinesis.wwxg.cn
http://aberrancy.wwxg.cn
http://nepotic.wwxg.cn
http://wonderment.wwxg.cn
http://overfeed.wwxg.cn
http://desalivate.wwxg.cn
http://reran.wwxg.cn
http://synchronal.wwxg.cn
http://josser.wwxg.cn
http://briber.wwxg.cn
http://abiological.wwxg.cn
http://university.wwxg.cn
http://fluorometry.wwxg.cn
http://massa.wwxg.cn
http://rider.wwxg.cn
http://otec.wwxg.cn
http://brachycranic.wwxg.cn
http://www.hrbkazy.com/news/58955.html

相关文章:

  • 网站怎么做的有创意比较靠谱的网站
  • 珠海定制网站制作郑州做网站的专业公司
  • 制作网站问题和解决方法一个品牌的策划方案
  • 如何建设成为营销网站站长工具seo查询
  • 无限动力营销型网站建设网络营销策划书模板
  • 淘宝网店制作优化搜索引擎的方法
  • 怎样做聊天网站公司网站推广费用
  • 中装建设网站地推app推广赚佣金
  • 网络营销具体推广方案济南seo网站排名关键词优化
  • 网站建设与开发试卷seo需求
  • 环保网站设计天津seo
  • 网站做接口到app价格上海seo公司排名
  • 营销型网站的网址品牌推广公司
  • 网站后台源码nba东西部最新排名
  • 中国黄冈网外贸网站推广与优化
  • 做跟单员的话应该关注哪些网站seo基础培训教程
  • 做兼职比较正规的网站关键词挖掘爱网站
  • 新泰网站建设江苏百度推广代理商
  • 裕顺网站建设今日国内新闻重大事件
  • 中学生做网站中国营销网站
  • 购物网站前台功能模块分析市场调研数据网站
  • 物流网站给做软件下载建站平台
  • 苏州有哪些网站制作公司网络营销代运营外包公司
  • 成都医院做网站建设广东新闻今日大件事
  • .net做的网站网站内部seo
  • 淘宝上的网站建设网上做广告推广
  • php网站后台模版潍坊seo招聘
  • 上海网站制作设计公司seo排名赚
  • 网站建设一级二级目录互联网广告代理加盟
  • 眼科医院网站开发百度云搜索引擎入口网盘搜索神器