J
J
jxs2018-09-10 11:39:53
Angular
jxs, 2018-09-10 11:39:53

How to filter data by id for a specific element?

There is a page that displays a certain "object". And I want to display a few more of its "object" on the page of this "object", which are linked by child identifiers.
Here is a small JSON example:

[{"object_id":1128,"ch_objects_id":null, "name":TestTitul},
{"object_id":2341,"ch_objects_id":1128, "name":Test2}]

Here at the moment is my version of how I wanted to do it, but it is not correct and not working (an empty array is displayed).
service:
get_filter_show_Objects(): Observable<Object[]> {
    return this.authService.get('objects')
    .map((response: Response) => <Object[]>response.json()
    .filter((object) => object.object_id == object.ch_objects_id))
}

getObject(id: number) {
    return this.authService.get('objects' + "/" + id + '.json').catch(this.handleError);
}

component:
objects: Array<Object>;
  id: number;
  routeId: any;
  returnUrl: string;
  public errorMsg;
  @Input() object: Object;

      ngOnInit() {
        this.loadObjects();

        this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/object';
        this.routeId = this.route.params.subscribe(
          params => {
            this.id = +params['id'];
          }
        )
        let objectRequest = this.route.params
          .flatMap((params: Params) =>
            this.servObject.getObject(+params['id' ]));
        objectRequest.subscribe(response => this.object = response.json());
      }

      private loadObjects() {
        this.servObject.get_filter_show_Objects().subscribe(
          (data: Object[]) => {
            console.log(data);
            this.objects = data;
          }
        );
      }

How to correctly implement a filter that will display a list of data and be linked by child id for the page of a specific "object"?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question