I am having trouble with the "removeCartItem" function. I am trying to get the "itemTitle" so that I can send it to the server to remove the item from the customer's cart. However, "itemTitle" is showing as undefined.
JS
$(function () {
function CartItem() {
var self = this;
self.itemTitle = ko.observable();
self.cartItemID = ko.observable();
self.price = ko.observable();
self.qty = ko.observable();
self.img = ko.observable();
self.lineTotal = ko.observable();
}
function viewModel(cartData) {
var self = this;
self.cartItems = ko.observableArray([]);
self.addItemToCart = function (listingID, qty) {
$.ajax({
url: '@Url.Action("phoneAdd","ShoppingCart",null)',
type: 'POST',
data: { 'listingID': listingID, 'requestedQty': qty },
success: function (data) {
alert(data.status);
}
});
};
self.removeCartItem = function (CartItem) {
alert(CartItem.price);
};
self.loadCartData = function () {
$.getJSON('@Url.Action("koShoppingCartItems","ShoppingCart",null)', function (data) {
$.each(data, function () {
alert(data);
self.cartItems.push({
itemTitle: ko.observable(this.itemTitle),
price: ko.observable(this.Price),
qty: ko.observable(this.Quantity),
lineTotal: ko.observable(this.lineTotal)
});
});
});
}
self.loadCartData();
}
ko.applyBindings(new viewModel());
});
HTML
<a href='#' data-bind='click: $parent.removeCartItem'>Remove</a>