Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4830

Delete Multiple records

$
0
0

@Fernanda_Silva wrote:

Hello:

I have a table with checkbox where user can select up to 20 records and delete all at once.

deleteSelectedUsers() { const selectedUsers = this.get('selectedUsers'); const userId = this.get('selectedUsers').mapBy('id');

  userId.forEach((item) => {
    this.get('ajax').request(`/api/v1/users/${item}`, {
      method: 'DELETE',
      data: { userId: item}
    }).then(() => {
      selectedUsers.forEach((d) => d.unloadRecord());
      selectedUsers.clear();
      this.set('confirmDelete', false);
      this.flashMessages.success('Users deleted');
    })
    .catch((err) => {
      console.log('err deleting User', err);
      this.flashMessages.danger('Failed to delete users');
    });
  });
},

This works fine, however it makes a call for each item selected in the table. Is there a way to wrap everything app and make one call to the server, therefore only generating one success message?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4830

Trending Articles