【问题标题】:react-sortable-tree: code doesn't display anythingreact-sortable-tree:代码不显示任何内容
【发布时间】:2021-07-24 15:44:27
【问题描述】:

我正在使用 reactjs 17,但我不知道为什么这段代码没有显示任何内容。

import React, { Component } from 'react';
import SortableTree from 'react-sortable-tree';
import 'react-sortable-tree/style.css';

export default class Tree extends Component {
  constructor(props) {
    super(props);
    this.state = {
      treeData: [
        { title: 'Chicken', children: [{ title: 'Egg' }] },
        { title: 'Fish', children: [{ title: 'fingerline' }] },
      ],
    };
  }

  render() {
    return (
      <div style={{ height: 400 }}>
        <SortableTree
          treeData={this.state.treeData}
          onChange={treeData => this.setState({ treeData })}
        />
      </div>
    );
  }
}

【问题讨论】:

  • 你能告诉我们你是如何渲染Tree组件的吗?
  • 导入'./App.css';从'./Tree'导入树;函数 App () { return (
    ); } 导出默认应用;
  • 设置外部 div 样式为&lt;div style={{ height: 400, width: 500, border: '1px solid red' }}&gt; 看到 div 本身了吗?
  • 是的,我看到了 div,但里面是空的
  • 同样的事情发生在我身上:C有什么更新吗?

标签: reactjs drag-and-drop frontend treeview


【解决方案1】:

为 React 17+ 使用以下包

react-sortable-tree for React 17+

【讨论】:

    猜你喜欢
    • 2021-09-03
    • 2022-11-16
    • 1970-01-01
    • 2011-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 2023-03-05
    相关资源
    最近更新 更多