- KnockoutJS Essentials
- Jorge Ferrando
- 299字
- 2021-07-23 20:16:16
Preparing the project
We can begin from the project we did in Chapter 1, Refreshing the UI Automatically with KnockoutJS. First of all, we are going to add some style to the page. Add a file called style.css
into the css
folder. Add a reference in the index.html
file, just below the bootstrap
reference. The following is the content of the file:
.container-fluid { margin-top: 20px; } .row { margin-bottom: 20px; } .cart-unit { width: 80px; } .btn-xs { font-size:8px; } .list-group-item { overflow: hidden; } .list-group-item h4 { float:left; width: 100px; } .list-group-item .input-group-addon { padding: 0; } .btn-group-vertical > .btn-default { border-color: transparent; } .form-control[disabled], .form-control[readonly] { background-color: transparent !important; }
Now remove all the content from the body tag except for the script tags and paste in these lines:
<div class="container-fluid"> <div class="row" id="catalogContainer"> <div class="col-xs-12" data-bind="template:{name:'header'}"></div> <div class="col-xs-6" data-bind="template:{name:'catalog'}"></div> <div id="cartContainer" class="col-xs-6 well hidden" data-bind="template:{name:'cart'}"></div> </div> <div class="row hidden" id="orderContainer" data-bind="template:{name:'order'}"> </div> <div data-bind="template: {name:'add-to-catalog-modal'}"></div> <div data-bind="template: {name:'finish-order-modal'}"></div> </div>
Let's review this code.
We have two row classes. They will be our containers.
The first container is named with the id
value as catalogContainer
and it will contain the catalog view and the cart. The second one is referenced by the id
value as orderContainer
and we will set our final order there.
We also have two more <div>
tags at the bottom that will contain the modal dialogs to show the form to add products to our catalog (the one we built in Chapter 1, Refreshing the UI Automatically with KnockoutJS) and the other one will contain a modal message to tell the user that our order is finished.
Along with this code you can see a template binding inside the data-bind
attribute. This is the binding that Knockout uses to bind templates to the element. It contains a name
parameter that represents the ID of a template.
<div class="col-xs-12" data-bind="template:{name:'header'}"></div>
In this example, this <div>
element will contain the HTML that is inside the <script>
tag with the ID header
.
- Getting Started with React
- Java 開(kāi)發(fā)從入門到精通(第2版)
- 軟件界面交互設(shè)計(jì)基礎(chǔ)
- 算法訓(xùn)練營(yíng):入門篇(全彩版)
- Practical Game Design
- Unity 5.x By Example
- D3.js 4.x Data Visualization(Third Edition)
- Citrix XenServer企業(yè)運(yùn)維實(shí)戰(zhàn)
- Beginning C++ Game Programming
- C語(yǔ)言程序設(shè)計(jì)實(shí)訓(xùn)教程與水平考試指導(dǎo)
- UI動(dòng)效設(shè)計(jì)從入門到精通
- 開(kāi)源網(wǎng)絡(luò)地圖可視化:基于Leaflet的在線地圖開(kāi)發(fā)
- Learning Scrapy
- 算法學(xué)習(xí)與應(yīng)用從入門到精通
- Mastering Web Application Development with Express