Без долгих раздумий и задержек я сделал следующее, что, кажется, работает, но не получил набор результатов за один раз. Вот фрагмент кода, который у меня есть:
Код: Выделить всё
//This works selecting a drop down box value
filterUsers() {
this.filteredUsers.items = [...this.dataSrc.items.filter(x => this.filterUsersFunc(x, this.filterState))]; //Initial values are here when drop down box selection done
this.filteredUsers.total = this.filteredUsers.items.length;
console.log("Filtered Users below:");
console.log(this.filteredUsers.items);
//Depending upon initial values and iterating them, like to have user permission for multiple users
for (var i = 0; i < this.filteredUsers.items.length; i++) {
this.userId = 0;
console.log(this.filteredUsers.items[i].id);
this.userId = this.filteredUsers.items[i].id;
this.userService
.getExploreUserPermissionSettings(this.filteredUsers.items[i]?.id, this.filteredUsers.items[i]?.enterpriseId) //Passing parameters from the loop
.pipe(finalize(() => this.busy = false))
.subscribe((response) => {
console.log("User Ids:");
console.log(this.filteredUsers.items[i]?.id);
let obj = {} as ExploreUserPermissionSettingItemArr; //Then trying to save them in an object
obj.userId = this.userId; //Even the user id doesn't get changed in each iteration, it only takes the last user id each time
obj.newArr = response.data.included;
console.log("In For Loop:");
console.log(obj);
this.userPermissionsIncluded.push(obj); //Finally adding them to an array
});
}
console.log("User Permissions Below:");
console.log(this.userPermissionsIncluded); //Lastly trying to see the result set
}

Я знаю, я делаю здесь что-то не так. Но есть ли способ получить поток за один раз и сразу сохранить его в массиве? Допустим, у меня есть 20 пользователей, участвующих в фильтрации, и эти 20 пользователей должны находиться в массиве, а не повторяться один за другим, как сейчас, как показано на снимке экрана.
Еще одна вещь. получите идентификаторы пользователей из цикла for, и он правильно передаст идентификатор контроллеру. Но когда я сохраняю его в объект obj.userId = this.userId;, он устанавливает только последний идентификатор пользователя из цикла, как вы можете видеть на снимке экрана.
Подробнее здесь: https://stackoverflow.com/questions/792 ... rvice-call
Мобильная версия