chap2->Creating templates->The header template

chap2
jason.zhu 2021-05-27 05:43:48 +00:00
parent 61c3776031
commit 4b8c3312f0
2 changed files with 29 additions and 1 deletions

View File

@ -26,7 +26,24 @@
</div> </div>
<!-- templates --> <!-- templates -->
<script type="text/html" id="header"></script> <script type="text/html" id="header">
<h1>Catalog</h1>
<button
class="btn btn-primary btn-sm"
data-toggle="modal"
data-target="#addToCatalogModal"
>
Add New Product
</button>
<button
class="btn btn-primary btn-sm"
data-bind="click: showCartDetails, css:{ disabled: cart().length < 1}"
>
Show Cart Details
</button>
<hr />
</script>
<script type="text/html" id="catalog"></script> <script type="text/html" id="catalog"></script>
<script type="text/html" id="add-to-catalog-modal"></script> <script type="text/html" id="add-to-catalog-modal"></script>
<script type="text/html" id="cart-widget"></script> <script type="text/html" id="cart-widget"></script>

View File

@ -41,11 +41,22 @@ var vm = (function () {
return filtered; return filtered;
}); });
var cart = ko.observableArray([]);
var showCartDetails = function () {
if (cart().length > 0) {
$("#cartContainer").removeClass("hidden");
}
};
return { return {
// first chapter
searchTerm: searchTerm, searchTerm: searchTerm,
catalog: filteredCatalog, catalog: filteredCatalog,
newProduct: newProduct, newProduct: newProduct,
addProduct: addProduct, addProduct: addProduct,
// second chapter
cart: cart,
showCartDetails: showCartDetails
}; };
})(); })();
ko.applyBindings(vm); ko.applyBindings(vm);