Skip to content

Instantly share code, notes, and snippets.

@ChrisMoney
Last active December 14, 2017 20:15
Show Gist options
  • Save ChrisMoney/aadd7a27ff82eb5081a1a658197ae124 to your computer and use it in GitHub Desktop.
Save ChrisMoney/aadd7a27ff82eb5081a1a658197ae124 to your computer and use it in GitHub Desktop.
Create Object in Knockout
function Attachment(data) {
this.id = ko.observable(data.AttachmentId);
this.name = ko.observable(data.AttachmentName);
this.size = ko.observable(data.AttachmentSizeText);
this.isEmail = ko.observable(data.IsEmail);
}
// map data object from server to Knockout object
var mappedAttachments = $.map(data.detail.Attachments, function (item) { return new Attachment(item); });
self.attachments(mappedAttachments);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment