首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于角的Kendo树视图的异步加载

基于角的Kendo树视图的异步加载
EN

Stack Overflow用户
提问于 2019-09-25 12:19:02
回答 1查看 402关注 0票数 0

我试图从外部源加载分层树视图,但是加载第一个节点childs时遇到了困难,最容易加载的是内部childs (但这一点我还不知道)。

数据是通过axios加载的,因此RxJS可观察的方法无法工作。我尝试了不同的东西,但是当我扩展第一个节点时,旋转器一直在旋转直到永恒。

我尝试过的一些观点

childeren

  • Tried试图为父节点分配异步修饰符

  • 尝试使用hasChilderen函数

进行许多不同的操作

希望有人能给我指明正确的方向。

我的代码:

tree.component.html

代码语言:javascript
复制
<kendo-treeview [nodes]="locations | async" [textField]="['shortName']" kendoTreeViewExpandable
  [hasChildren]="hasChildren.bind(this)" [children]="fetchChildren.bind(this)">
</kendo-treeview>

tree.component.ts

代码语言:javascript
复制
export class TreeComponent implements OnInit {
  public locations: Promise<Location[]>

  constructor(private locationService: LocationService,
    private cdRef: ChangeDetectorRef) { }

  ngOnInit() {
    this.locations = this.locationService.getBaseLocation();
  }

  public hasChildren = (item: Location): boolean => item.hasChildLocations;

  public fetchChildren = (item: Location): Promise<Location[]>  => this.locationService.getChildLocations(item.locationId);
}

location.service.ts

代码语言:javascript
复制
export class LocationService {
  async getBaseLocation(): Promise<Location[]> {
    return await axios.get<Location>('/Location/GetBaseLocation')
      .then((response: AxiosResponse<Location>) => {
        return [response.data];
      });
  }

  async getChildLocations(locationId: string): Promise<Location[]> {
    return await axios.get<Location[]>(`/Location/GetLocationTree?UpperLocationID=${locationId}`)
      .then((response: AxiosResponse<Location[]>) => response.data);
  }
}

location.model.ts

代码语言:javascript
复制
export interface Location {
    locationId: string;
    upperLocationId: string;
    locationTypeId: number;
    shortName: string;
    plantCode: string;
    hasChildLocations: boolean;

    icon: string;
    isSelected: boolean;

    childeren: Location[];
}

纺纱机一直在滚动

控制台在从外部服务加载我的子程序之前输出一个错误,所以我的5分钱是基于这样一个事实:角试图在节点加载之前展开它们。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-26 09:05:10

简单的解决办法:

变化

代码语言:javascript
复制
public fetchChildren = (item: any) this.locationService.getChildLocations(item.locationId);

代码语言:javascript
复制
  public fetchChildren = (item: any) => from(this.locationService.getChildLocations(item.locationId));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58098228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档