Created
May 22, 2020 12:09
-
-
Save blubbll/7f84c6b622e1562cb685c4c4860f2736 to your computer and use it in GitHub Desktop.
knockoutjs tutorial 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const api = `${location.protocol}//${location.href.split("//")[1].split("/")[0]}`; | |
console.clear(); | |
function WebmailViewModel() { | |
// Data | |
var self = this; | |
self.folders = ['Inbox', 'Archive', 'Sent', 'Spam']; | |
self.chosenFolderId = ko.observable("Inbox"); | |
self.chosenFolderData = ko.observable(); | |
self.chosenMailData = ko.observable(); | |
// Behaviours | |
self.goToFolder = folder => { | |
self.chosenFolderId(folder); | |
let url = new URL(`${api}/mail`), | |
params = { | |
folder | |
}; | |
Object.keys(params).forEach(key => url.searchParams.append(key, params[key])), | |
f = fetch(url).then(r => r.json()) | |
.then(self.chosenFolderData); | |
/*$.get('/mail', { | |
folder: folder | |
}, self.chosenFolderData);*/ | |
}; | |
}; | |
ko.applyBindings(new WebmailViewModel()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment