In Durandal, I'm working on a page that lists a number of doctors. Each row has a delete button. Here's my View Model:
var Doctor = function() {};
Doctor.Model = function(data) {
this.id = data.id;
this.name = ko.observable(data.name);
};
Doctor.prototype.activate = function() {
this.doctorArr = ko.observableArray();
// Start Doctor List
this.load();
};
Doctor.prototype.load = function() {
// load list into this.doctorArr()
}
Doctor.prototype.remove = function() {
console.log(this);
};
And here's my View:
<button data-bind="click: remove">Remove Function</button>
<ul data-bind="foreach: { data: doctorArr }">
<li>
<span data-bind="text: name"></span> - <a data-bind="click: $parent.remove">Delete...</a>
</li>
</ul>
Clicking on the <button> will return:
Doctor {doctorArr: function, activate: function…}
But clicking on the link inside the foreach function will return the model:
Doctor.Model {id: "104", name: function}
The problem is that I can't figure out how to access doctorArr from inside the remove function when 'this' returns the Model. I need it to remove the item.