Skip to content

Instantly share code, notes, and snippets.

@alvarotrigo
Created August 13, 2015 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvarotrigo/151fabf2d5d0e789aafc to your computer and use it in GitHub Desktop.
Save alvarotrigo/151fabf2d5d0e789aafc to your computer and use it in GitHub Desktop.
function User(userData) {
userData = userData || {};
this.name = ko.observable(userData.name);
//copying all non existent properties
for(var key in userData) {
if(!self.hasOwnProperty(key)) {
self[key] = userData[key];
}
}
}
function UsersViewModel() {
var myData = [{
id: "001",
name: "Jhon",
status: "Single"
}, {
id: "002",
name: "Mike",
status: "Married"
}, {
id: "003",
name: "Marrie",
status: "Complicated"
}];
self.users = ko.observableArray(myData.map(function(userData) {
return new User(userData);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment