I am going through the tutorial from the official website:
Knockout single page application lesson
this is the view:
<!-- Folders -->
<ul class="folders" data-bind="foreach: folders">
<li data-bind="text: $data,
css: { selected: $data == $root.chosenFolderId() },
click: $root.goToFolder"></li>
</ul>
and the script:
function WebmailViewModel() {
// Data
var self = this;
self.folders = ['Inbox', 'Archive', 'Sent', 'Spam'];
self.chosenFolderId = ko.observable();
// Behaviours
self.goToFolder = function(folder) { self.chosenFolderId(folder); };
};
ko.applyBindings(new WebmailViewModel());
I dont' t understand 2 things:
the 'click:' event is calling the javascript function goToFolder, however, with no argument, how does it know which folder is clicked to set the chosenFolderId ?
Correct me if I am wrong, the line css: { selected: $data == $root.chosenFolderId() } means if the current selected object $data is equal to chosenFolderId(), therefore the css with the name selected is enable ?
Cheers all