Ravi Ram
Ravi Ram

Reputation: 24498

Knockout JS Remove not working

I have some very basic binding .. working. Now I am trying to delete a row. It is not working.

http://jsfiddle.net/uC8Vt/57/

I am not passing the correct

var ClientModel = function () {

    this.clients = ko.observableArray(data); // Load json data

    self.del = function(elem) { 
        if (confirm('Delete:  ' + elem.Name)) {
            this.client.remove(elem);
        };
    }
}

I am not sure why the remove is not working.

Upvotes: 2

Views: 1647

Answers (2)

Brian B
Brian B

Reputation: 1551

For one thing - change this.client.remove(elem); to: self.clients.remove(elem);

You specified "this" instead of "self", and "client" instead of "clients"

Upvotes: 0

pomber
pomber

Reputation: 23990

The functions for selection and deletion are in the parent view model, so you should call them with $parent.select and $parent.del.

Also this line had some mistakes:

self.clients.remove(elem);

Here is the fixed jsfiddle.

Upvotes: 4

Related Questions