SentinelSixSpy SentinelSixSpy - 2 years ago 87
HTML Question

Delete multiple rows in JavaScript

I have a 'notifications app' in my program. In the app there is an 'alerts' section. Each alert has an option to delete the alert with a delete button on that row. The 'alerts' section also has a clear button. I want to make that clear button delete all of the alerts in the 'alerts' section. However I am having trouble doing this.

I need to make a change in

. I am just stumped on what I need to add. The 'alerts' are not being cleared still. I added where the
is being used. Maybe I need to add something here as well?

Answer Source

If I understand you correctly - you want to delete all notifications within one app - so iterating over appList is not necessary. Iterate over one app's notifications instead:

$scope.dismissAppNotifications = function(app) {
    var notifications = app.notifications;
    for (var id in notifications) {
      // may be reasonable to add checking for only own properties
        function(notificationId) { // outer function needed because of the way scopes and closures works in js
            return function (response) {
              delete app.notifications[notificationId];

notifications[id].id can be replaced with simply id if key and id property are the same.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download