Below is my view model code
var TopicsViewModel = function() {
var self = this;
var fakeTopicData = [];
self.Topic = function(area, name, link, desc, why) {
self.area = ko.observable(area ? area : "");
self.name = ko.observable(name ? name : "");
self.link = ko.observable(link ? link : "");
self.desc = ko.observable(desc ? desc : "");
self.why = ko.observable(why ? why : "");
};
self.createProfile = function () {
alert("came to create profile");
};
self.editProfile = function () {
alert("came to edit profile");
};
self.removeProfile = function (profile) {
alert("came to remove profile");
self.topicsArr.remove(profile);
};
var refresh = function () {
fakeTopicData.push(new self.Topic("Functional Prog", "Javascript", "http:\\www.somedummysite.com", "somedesc", "Just because"));
fakeTopicData.push(new Topic("ASP.NET ", "MVC5", "http:\\www.somedummysite.com", "somedesc2", "Just because2"));
self.topicsArr(fakeTopicData);
};
self.topicsArr = ko.observableArray([]);
refresh();
};
ko.applyBindings(new TopicsViewModel());
Here is my VIEW code
<hr />
<hr />
@*<input type="button" class="btn-sm" value="New Topic" data-bind="click:clickevent" />*@
<table class="table table-striped table-bordered table-condensed">
<tr >
<th>Area</th>
<th>Name</th>
<th>Link</th>
<th>Link</th>
<th>Description</th>
<th>Why</th>
</tr>
<tbody data-bind="foreach : topicsArr">
<tr>
<td data-bind="text:area"> </td>
<td class=""><a data-bind="text:name, click:$parent.editProfile"></a></td>
<td data-bind="text:link"> </td>
<td> <input data-bind="text:link"></> </td>
<td data-bind="text:desc"> </td>
<td data-bind="text:why" ></td>
<td><button class="btn btn-mini btn-danger" data-bind="click:$parent.removeProfile">remove</button></td>
</tr>
</tbody>
</table>
@* *@
I was hoping that when the user makes a change to the input field the value will be reflected in the model object. But when i run this app I get below error
0x800a139e - JavaScript runtime error: Unable to parse bindings.
Message: ReferenceError: 'area' is undefined;
Could someone please point me to what I am doing wrong here.
