Эта статья объединяет начальную загрузку для создания относительно полного приложения для управления списками продуктов, включая добавление продукта, удаление и модификацию.
Требуемые цитаты
<script type = 'text/javascript' src = 'http: //www.see-source.com/js/knockout-2.2.0.js'> </script> <script type = 'text/javascript' src = 'http: //www.see-source.com/js/jquery-1.6.2.min. href = "http://www.see-source.com/bootstrap/css/bootstrap.css" rel = "stylesheet">
HTML -код
<body> <!-Динамически сгенерировать список продуктов-> <table> <thead> <tr> <th> id </th> <Th> Название продукта </th> <Th> Оригинальная цена </th> <Th> Promotion Price </th> <Th> операция </th> </tr> </theAd> <tbody data-bind = "foreach: products"> <tre> <td> data-bind = "/$". </td> <td> <input type="text" data-bind="value: $data.Name"/> </td> <td> <input type="text" data-bind="value: $data.Price"/> </td> <td> <input type="text" data-bind="value: $data.ActualCost"/> </td> <td> <input type="button" value="Modify" data-bind="click: $root.update"/> <input type="button" value="Delete" data-bind="click: $root.remove"/> </td> </tbody></table><!-- Product Add form --><form data-bind="submit:$root.create"> <fieldset> <legend>Add product</legend> <div> <label for="input01">Product Имя </label> <div> <input type = "text" name = "name"> </div> </div> <div> <label для = "input01"> исходная цена </label> <div> <input type = "name =" price "> </div> </div> <div> <label для =" input01 "> rametional price </label> <div> <div> <dive name name =" intaint name name "=" intaint name "=" intaint name "=" intaint "=" natue "=" intaint name "=" intaint name "=" intaint name ". </div> </div> <div> <button Type = "Opport"> Сохранить </button> <tutry> Cancel </button> </div> </fieldset> </form> </body>
JS -код
<script type = "text/javascript"> function productsviewmodel () {var baseuri = 'http: // localhost: 8080/nockout/'; var self = это; // self.products = ko.observablearray ([{'' id ':' 111 ',' name ':' Lenovo K900 ',' Price ':' 3299 ',' ActualCost ':' 3000 '}, {' id ':' 222 ',' name ':' htc One ',' Price ':' 4850 ',' Actual ',', '4850', ',', ',', ',', ',', ',', ',', ',', ',', ',', ', Актуальный,', '4850', '4850': '4850': '4850': '4850': '4850': '4850': '4850': '4850': '4800 self.products = ko.observablearray (); $ .getJson (baseuri + "list", self.products); // загрузить список продуктов // Добавить продукт self.create = function (formElement) {$ .post (baseuri + "add", $ (formelement) .serialize (), функция (data) {if (data.success) {// uclide uepredpress uepredpress uccess) {//uct ucured. {}; } // Модифицировать продукт self.update = function (product) {$ .post (baseuri + "upplete", product, function (data) {if (data.success) {alert ("Modify успешно");}}, "json"); } // Удалить продукт self.remove = function (product) {$ .post (baseuri + "delete", "productId =" + product.id, function (data) {if (data.success) {// Когда удаление на стороне сервера успешно, self.products.Remove (product);}}}, "Json"); }}}} ko.applybindings (new ProductsViewModel ()); </script>Если вы все еще хотите учиться глубже, вы можете нажать здесь, чтобы изучить и прикрепить к вам 3 захватывающих тем:
Начальная учебник по обучению
Bootstrap Practical Rutorial
Учебное пособие по использованию плагина Bootstrap
Выше всего содержание этой статьи. Я надеюсь, что это будет полезно для каждого обучения, и я надеюсь, что все будут поддерживать Wulin.com больше.