Created
August 13, 2015 11:45
-
-
Save alvarotrigo/151fabf2d5d0e789aafc to your computer and use it in GitHub Desktop.
This file contains 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
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