knowledge.dart 799 B

123456789101112131415161718192021222324252627282930
  1. /// 知识点模型
  2. class KnowledgeNode {
  3. final String code;
  4. final String name;
  5. final List<KnowledgeNode> children;
  6. final String? fullPath;
  7. final bool isLeaf;
  8. KnowledgeNode({
  9. required this.code,
  10. required this.name,
  11. this.children = const [],
  12. this.fullPath,
  13. this.isLeaf = false,
  14. });
  15. factory KnowledgeNode.fromJson(Map<String, dynamic> json) {
  16. return KnowledgeNode(
  17. code: json['code'] ?? '',
  18. name: json['name'] ?? '',
  19. children: (json['children'] as List<dynamic>?)
  20. ?.map((c) => KnowledgeNode.fromJson(c as Map<String, dynamic>))
  21. .toList() ??
  22. [],
  23. fullPath: json['full_path'],
  24. isLeaf: json['full_path'] != null || (json['children'] == null || (json['children'] as List).isEmpty),
  25. );
  26. }
  27. }