首页 > 解决方案 > 不在 jstree 和 Angular 中显示列表

问题描述

我需要使用 Jstree 在 Angular6 中显示所有角色。

我从服务器获取所有列表,但它没有显示我任何东西。

我怎么解决这个问题?

我的代码:

索引中的配置:

<!doctype html>
<html lang="en">
   <head>
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" />
    <title>StoreAp</title>
    <base href="/">
  </head>
  <body>
    <app-root></app-root>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
  </body>
</html>

HTML:

<div class="addRole">
    <div id="jstree">

    </div>
</div>
<script>

  $('#jstree').on('changed.jstree',function(data){
          var i,j;
          var postItem =[];
          j=data.selected.lenght;
          for( i=0 ; i<j ; i++ )
          {
              var id=data.selected[i];
              postItem.push({
                text:data.instanse.get_node(data.selected[i]).text,
                id:id,
                parent:data.node.parents[0]
              });
          }
          $('#selectedItems').val(JSON.stringify(postItem));
      }).jstree({
        "core":{
          "theme":{
            "variant":"large"
          },
          "data":subroles
        },
        "checkbox":{
          "keep_selected_style":false
        },
        "plugin":["wholerow"]

      });

</script>

并在 .TS 文件中

export class AccessLevelComponent implements OnInit {

  public subroles:Isubrole[];

  constructor(private roleService:RoleServiceService) { }

  ngOnInit() {
    this.roleService.GetSubrole().subscribe((data)=>{
      this.subroles=data;
    });

  }
}

标签: javascriptjqueryangularangular6jstree

解决方案


推荐阅读