I am in the process of learning KnockoutJS and I have implemented code for folder navigation in a webmail client. In the view code, there is a comparison being made to check if the reference variable $data
and $root.chosenFolderId()
point to the same memory location. However, I am unsure about what the initial value of $root.chosenFolderId()
will be?
Reference
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());