Is it possible to manually insert a computed observable into an array that is generated with the mapping plugin? Here is an example that does not use the mapping plugin, but I would like to know if it could use it.
Lets say I have JSON data from the server:
[{
"OrderID":1,
"FirstName":"Bill",
"LastName":"Smith",
},{
"OrderID":2,
"FirstName":"Jeff",
"LastName":"Evans",
}
{
"OrderID":3,
"FirstName":"Dan",
"LastName":"Johnson",
}]
On my view I have an Order class and a view model:
function Order(order) {
var self = this;
self.OrderID = ko.observable(order.OrderID);
self.FirstName = ko.observable(order.FirstName);
self.LastName = ko.observable(order.LastName);
/*This is what I want to insert after the mapping plugin
generates "orders on the ViewModel*/
self.FullName = ko.computed(function () {
return self.FirstName() + ' ' + self.LastName();
});
}
function ViewModel() {
var self = this;
self.orders = ko.observableArray([])
//Get orders
$.ajax({
url: '@Url.Action("orders")',
type: "post",
success: function (data) {
var mappedOrders = $.map(data, function (item) { return new Order(item) });
self.orders(mappedOrders);
}
})
}
Is it possible to use the mapping plugin to generate the orders array on the view model, and also be able to insert the computed observable "FullName" in the orders array?