function Task(data) {
this.ID = ko.observable(data.ID);
this.Description = ko.observable(data.Description);
this.ClientName = ko.observable(data.ClientName);
this.ClientFK = ko.observable(data.ClientFK);
this.CustomerName = ko.observable(data.CustomerName);
this.CustomerFK = ko.observable(data.CustomerFK);
}
function Customer(data) {
this.CompanyName = ko.observable(data.CompanyName);
this.CustomerID = ko.observable(data.CustomerID);
this.AnzahlTasks = ko.observable(data.AnzahlTasks);
}
function TaskListViewModel() {
// Data
var self = this;
self.tasks = ko.observableArray([]);
self.customers = ko.observableArray([]);
$.getJSON("/api/CustomerList", function (allData) {
var mappedCustomer = $.map(allData, function (item) { return new Customer(item) });
self.customers(mappedCustomer);
});
// Load initial state from server, convert it to Task instances, then populate self.tasks
$.getJSON("/api/Task", function (allData) {
var mappedTasks = $.map(allData, function (item) { return new Task(item) });
self.tasks(mappedTasks);
});
}
ko.applyBindings(new TaskListViewModel());