I have just started learning KnockoutJS. This is code for folder navigation of webmail client.In the view code, a comparision is made whether the reference variable $data
and $root.chosenFolderId()
point to the same memory location. But I don't understand what will be the initial value of $root.chosenFolderId()
?
View:
<!-- Folders -->
<ul class="folders" data-bind="foreach: folders">
<li data-bind="text: $data, css : {selected: $data == $root.chosenFolderId()}, click: $root.goToFolder"></li>
</ul>
View Model:
function WebmailViewModel() {
// Data
var self = this;
self.folders = ['Inbox', 'Archive', 'Sent', 'Spam'];
self.chosenFolderId = ko.observable();
//Operations
self.goToFolder = function(folder){
self.chosenFolderId(folder);
};
};
ko.applyBindings(new WebmailViewModel());