I am trying to implement a shopping cart with knockoutjs.
My issue is whenever user navigates to other pages of website, the data in the shopping cart (which gets created using an observableArray) does not persists.
What I want is when user navigates away to different categories still, he/she should be able view the data ordered in previous category.
My HTML File:
<div class="orderSegement" data-bind="visible: viewOrderTab()">
<section>
<h2 class="hidden">Order</h2>
<article class="OrderedItems">
<div class="headindOrder headindOrderLeft0">Name</div><div class="headindOrder headindOrderLeft25">Price</div><div class="headindOrder headindOrderLeft50">Qty</div>
<div data-bind="foreach: orderList">
<div class="OrderData" data-bind="visible: ProductQty">
<label data-bind="text: ProductName"></label>
<label data-bind="text: ProductPrice"></label>
<label data-bind="text: ProductQty"></label>
<a href="#" data-bind="click: $root.removeFromList">Remove</a>
</div>
</div>
<label data-bind="visible: totalPrice, text: totalPrice"></label>
<button class="button" data-bind="click: viewOrder">Hide</button>
<button class="button" data-bind="visible: totalPrice, click: submitToServer">Order</button>
</article>
</section>
</div>
My viewModelFile
self.orderList = ko.observableArray(null, {persist: 'orderList'});
I was trying to achieve this via knockout.localStorage.js. However I have not been able to successfully implement it. Does knockout.localStorage.js is applicable only to ko.observable() variables? Or does it support ko.observableArray or ko.computed, if yes then how?