Skip to content

Instantly share code, notes, and snippets.

@rjmacarthy
Created April 16, 2015 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjmacarthy/0f2aac900f09efaacd7e to your computer and use it in GitHub Desktop.
Save rjmacarthy/0f2aac900f09efaacd7e to your computer and use it in GitHub Desktop.
Knockout Browserify
browserify app.js -o bundle.js
<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>
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;
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