chap1->The view-model->The model
1. Create separate model 'Product' 2. Place link to product.js in HTML at correct place 3. Learn & apply Revealing Module Pattern on both Product module and viewmodelchap2
parent
4e774c2585
commit
d7d701f343
|
@ -30,6 +30,7 @@
|
|||
<script type="text/javascript" src="js/bootstrap.js"></script>
|
||||
<script type="text/javascript" src="js/knockout-3.2.0.js"></script>
|
||||
<!-- app -->
|
||||
<script type="text/javascript" src="js/models/product.js"></script>
|
||||
<script type="text/javascript" src="js/viewmodel.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
var Product = function (id, name, price, stock) {
|
||||
"use strict";
|
||||
var _id = id,
|
||||
_name = name,
|
||||
_price = price,
|
||||
_stock = stock;
|
||||
return {
|
||||
id: _id,
|
||||
name: _name,
|
||||
price: _price,
|
||||
stock: _stock,
|
||||
};
|
||||
};
|
|
@ -1,9 +1,7 @@
|
|||
var vm = {
|
||||
product: {
|
||||
id: 1,
|
||||
name: 'T-Shirt',
|
||||
price: 10,
|
||||
stock: 20
|
||||
}
|
||||
var vm = (function() {
|
||||
product: Product(1, 'T-Shirt', 10, 20);
|
||||
return {
|
||||
product: product
|
||||
};
|
||||
})();
|
||||
ko.applyBindings(vm);
|
Loading…
Reference in New Issue