Artikel ini menggabungkan bootstrap untuk membuat aplikasi yang relatif lengkap untuk mengelola daftar produk, termasuk penambahan produk, penghapusan, dan modifikasi.
Kutipan yang Diperlukan
<type script = '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/js =' http: //www.see-source.com/js/js/script =.jquer..jo..jo..jo..jo..js.js.js..js.js.js..js.js..js.js.js.js.js. href = "http://www.see-source.com/bootstrap/css/bootstrap.css" rel = "stylesheet">
Kode HTML
<body><!-- Dynamically generate product list--><table> <thead> <tr> <th>ID</th> <th>Product name</th> <th>Original price</th> <th>Promotion price</th> <th>Operation</th> </tr> </thead> <tbody data-bind="foreach: products"> <tr > <td> <span data-bind="text: $data.Id"></span> </td> <td> <input type = "text" data-bind = "value: $ data.name"/> </td> <td> <input type = "text" data-bind = "value: $ data.price"/> </tpon> <td> <input type = "Text" data-bind = "value: $ data." 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 untuk = "input01"> Nama produk </label> <v div> <input type = "text" name = "name"> </div> </div> <v div> <label untuk = "input01"> Harga asli </label> <Div> <input type = "Text" name = "Price"> </Div> </Div> <Div> <input for = "Text" name = "Price"> </Div> </Div> <Div> <Div> <input for = "Text" name = "Price" name = "AcctualCost"> </div> </div> <veT> <Tombol type = "Kirim"> Simpan </buttom> <button> Batal </button> </div> </fieldset> </form> </body>
Kode JS
<script type = "text/javascript"> function ProductViewModel () {var baseuri = 'http: // localhost: 8080/knockout/'; var self = ini; //self.products = ko.observableArray ([{'id': '111', 'name': 'lenovo k900', 'price': '3299', 'aktualkos': '3000'}, {'id': '222', 'nama': 'htc', '{' Id ':' 48. self.products = ko.observableArray (); $ .getjson (baseuri + "Daftar", self.products); // Muat daftar produk // Tambahkan produk self.create = function (formeLement) {$ .post (baseuri + "add", $ (formeLement) .serialize (function (data) {if (data.success) {//side-s-side (Data) {if (data. {}; } // Ubah produk self.update = function (produk) {$ .post (baseuri + "update", produk, fungsi (data) {if (data.success) {alert ("Modifikasi berhasil");}, "json"); } // hapus produk self.remove = function (produk) {$ .post (baseuri + "delete", "productId =" + product.id, function (data) {if (data.success) {// Ketika penghapusan sisi server berhasil, self.products.remove (produk);}}, "json); }}}} ko.ApplyBindings (ProductSViewModel ()); </script>Jika Anda masih ingin belajar secara mendalam, Anda dapat mengklik di sini untuk mempelajari dan melampirkan 3 topik menarik kepada Anda:
Tutorial Pembelajaran Bootstrap
Tutorial Praktis Bootstrap
Tutorial Penggunaan Plug-In Bootstrap
Di atas adalah semua konten artikel ini. Saya berharap ini akan membantu untuk pembelajaran semua orang dan saya harap semua orang akan lebih mendukung wulin.com.