Answer the question
In order to leave comments, you need to log in
How to clone an array with an object?
There is a function that accepts an array of objects:
setDefault(defaultFilters: Filter[]) {
this.defaultFilters = defaultFilters;
}
export class Filter implements FilterModel {}
this.defaultFilters = {...defaultFilters};
export abstract class FiltersRepository {
public _filters: Filter[] = [];
private filtersResponse: Filter[] = [];
public filters$ = new Subject<Filter[]>();
private filterUrlBuilder = new FilterUrlBuilder();
private changes$ = new BehaviorSubject<string>(null);
private default: Filter[];
abstract init();
setDefault(defaultFilters: Filter[]) {
this.default = defaultFilters.slice();
this._filters = defaultFilters;
}
modifyDefault() {
this._filters.forEach((_filter) => {
this.filtersResponse.forEach((responseFilter) => {
if (_filter.title === responseFilter.title) {
if (Array.isArray(responseFilter.collection) && responseFilter.collection.length) {
_filter.collection = responseFilter.collection;
}
}
});
});
}
reset() {
console.log(this.default);
this._filters = this.default;
this.filter();
}
}
Answer the question
In order to leave comments, you need to log in
How to clone the defaultFilters object?
defaultFilters
is an array. defaultFilters.slice();
defaultFilters.map(instance => instance.clone());
clone
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question