antd 集成第三方js控件

主思路

使用js集成原始的jsoneditor

详情

集成第三方js控件 jsoneditor,有两个选择 原始的 jsoneditor

GitHub - josdejong/jsoneditor: A web-based tool to view, edit, format, and validate JSON

已经包装为 react 的 jsoneditor-react

GitHub - vankop/jsoneditor-react: react wrapper implementation for https://github.com/josdejong/jsoneditor

后来还是选择用原始jsoneditor,可控性大一点,而且直接集成了ace比较方便。jsoneditor-react里不包括ace,需要另外引入。

ScriptEditor 就是为了换个名字, mode其实是可以引入参数的,这段来自官方的example

import React, { Component } from 'react';
import JSONEditor from 'jsoneditor';

import 'jsoneditor/dist/jsoneditor.css';

import './index.less';

export default class ScriptEditor extends Component {
  componentDidMount() {
    const options = {
      mode: 'code',
      onChangeJSON: this.props.onChangeJSON,
    };

    this.jsoneditor = new JSONEditor(this.container, options);
    this.jsoneditor.set(this.props.json);
  }

  componentWillUnmount() {
    if (this.jsoneditor) {
      this.jsoneditor.destroy();
    }
  }

  componentDidUpdate() {
    this.jsoneditor.update(this.props.json);
  }

  render() {
    return <div className="jsoneditor-react-container" ref={(elem) => (this.container = elem)} />;
  }
}

遇到 ide的报警问题,可以简单地在 typing.d.ts 里定义一下。

declare module 'jsoneditor';

参考

官方 GitHub - josdejong/jsoneditor: A web-based tool to view, edit, format, and validate JSON

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值