官术网_书友最值得收藏!

  • KnockoutJS by Example
  • Adnan Jaswal
  • 362字
  • 2021-07-09 21:55:32

Creating the skeleton

We need to create the skeleton before we can start building the application features. Follow the steps given to create the skeleton. You should be familiar with these steps from the previous chapter.

Create the folder structure for development by following these steps.

  1. Create the ToDoList folder. This is the main folder that houses our to-do list application.
  2. Add a WebContent folder under the ToDoList folder. This folder holds the content that gets published to the web.
  3. Add a javascript folder under the WebContent folder. As the folder name suggests, this folder will contain all our JavaScript files.
  4. Add bootstrap folder under the WebContent folder. This folder will contain the Bootstrap files.

Now that we have the folder structure in place, let's add the files to our folders by following these steps:

  1. Add the Knockout library to the javascript folder.
  2. Add the JQuery library to the javascript folder.
  3. Add Bootstrap to the bootstrap folder.
  4. Create the file todolist.js under the javascript folder.
  5. Create the todolist.html file under the WebContent folder.

Following these preceding steps should result in a folder structure that looks similar to this:

Creating the skeleton

Now that we have created the folder structure, we can add code to our HTML and JavaScript files. Open the todolist.html file and add the following HTML code:

<!DOCTYPE HTML>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html" />
    <title>Knockout : ToDo List Example</title>

    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">

    <script type="text/javascript" src="javascript/jquery-2.1.3.min.js"></script>
    <script type="text/javascript" src="javascript/knockout-3.2.0.js"></script>
    <script type="text/javascript" src="javascript/todolist.js"></script>

  </head>
  <body>
    <div class="container">
      <div class="page-header">
        <h1>My ToDo List</h1>
      </div>
    </div>
  </body>
</html>

The preceding code references the required libraries and displays a page header with the name of our application—My ToDo List. Open the todolist.js file and add the following code. This code defines our empty ToDoList module:

/* Module for ToDo List application */
var ToDoList = function () {

  /* add members here */

  var init = function () {
    /* add code to initialize this module */
  };

  /* execute the init function when the DOM is ready */
  $(init);

  return {
    /* add members that will be exposed publicly */
  };
}();

View the application in the browser. It should give you a page with the page header. We are now ready to create the functionality to add and view tasks.

Let's get started and build the first feature of our to-do list application.

主站蜘蛛池模板: 平塘县| 巨鹿县| 海伦市| 迁西县| 石棉县| 庄浪县| 叙永县| 西昌市| 鸡东县| 高邮市| 安仁县| 成武县| 金坛市| 芜湖县| 和田市| 合阳县| 抚松县| 库尔勒市| 石城县| 建瓯市| 临颍县| 顺昌县| 邛崃市| 临汾市| 毕节市| 三门县| 涞水县| 乐陵市| 明溪县| 通化市| 张家港市| 四平市| 衡阳市| 永兴县| 元朗区| 株洲县| 原平市| 扎兰屯市| 莲花县| 咸宁市| 自治县|