Created
April 16, 2015 09:59
-
-
Save rjmacarthy/0f2aac900f09efaacd7e to your computer and use it in GitHub Desktop.
Knockout Browserify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
browserify app.js -o bundle.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | |
<body> | |
<div id="test"> | |
<div data-bind="text : person.name"></div> | |
</div> | |
</body> | |
</html> | |
<script src="bundle.js" ></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ko = require('knockout'); | |
var bind = function(element, viewModel) { | |
var el = document.getElementById(element); | |
var vm = new viewModel(); | |
ko.applyBindings(vm, el); | |
} | |
exports.bind = bind; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var komapping = require('knockout.mapping'); | |
var koUtils = require('./koUtils'); | |
var ViewModel = function(first, last) { | |
var self = this; | |
var personObj = {'name' : 'richard'}; | |
this.person = komapping.fromJS(personObj); | |
}; | |
koUtils.bind('test', ViewModel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment