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/bootstrap.js"></script>
|
||||||
<script type="text/javascript" src="js/knockout-3.2.0.js"></script>
|
<script type="text/javascript" src="js/knockout-3.2.0.js"></script>
|
||||||
<!-- app -->
|
<!-- app -->
|
||||||
|
<script type="text/javascript" src="js/models/product.js"></script>
|
||||||
<script type="text/javascript" src="js/viewmodel.js"></script>
|
<script type="text/javascript" src="js/viewmodel.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</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 = {
|
var vm = (function() {
|
||||||
product: {
|
product: Product(1, 'T-Shirt', 10, 20);
|
||||||
id: 1,
|
return {
|
||||||
name: 'T-Shirt',
|
product: product
|
||||||
price: 10,
|
|
||||||
stock: 20
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
})();
|
||||||
ko.applyBindings(vm);
|
ko.applyBindings(vm);
|
Loading…
Reference in New Issue