I have a view model Which has to be attached to a click event of an <li>
tag. Here is the viewmodel and markup
var viewModel =
{
Folders: ['Inbox', 'Archive', 'Sent', 'Spam'],
SelectedFolder: ko.observable('Inbox'),
chosenFolderId: ko.observable(),
navigate: function () {
self.chosenFolderId(folder);
}
};
ko.applyBindings(viewModel);
And the markup is
<ul class="nav nav-list bs-docs-sidenav affix" data-bind="foreach:Folders">
@*<li data-bind="css:{active: $data == chosenFolderId() }">*@
<li>
<a href="#" data-bind="click:navigate">
<!-- ko text: $data -->
<!-- /ko -->
<i class="icon-chevron-right"></i>
</a>
</li>
</ul>
The problem is in this line
<a href="#" data-bind="click:navigate">
and
<li data-bind="css:{active: $data == chosenFolderId() }">
Both The line above is not getting attached to the Navigate
function and chosenFolderId
observable respectively. It says Navigate
is undefined . It cannot be parsed. Same goes for
chosenFolderId`.
Any idea why is it happening ?