Unable to parse binding attribute
https://groups.google.com/d/topic/knockoutjs/0LvK7gF9KBQ/discussion
by rniemeyer
HTML
<script src="https://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.js"></script>
<script src="http://knockoutjs.com/downloads/knockout-2.2.1.js"></script>
First name: <input data-bind="valueWithInit: 'firstName'" /><br/>
Last name: <input data-bind="valueWithInit: 'lastName'"/>
<hr/>
<div data-bind="text: ko.toJSON(viewModel) "></div>
CSS
input { margin: 2px; }
JavaScript
var viewModel = {
};
//create an observable if it does not exist and populate it with the input's value
ko.bindingHandlers.valueWithInit = {
init: function(element, valueAccessor, allBindingsAccessor, data) {
var property = valueAccessor(),
value = element.value;
//create the observable, if it doesn't exist
if (!ko.isWriteableObservable(data[property])) {
data[property] = ko.observable();
}
data[property](value);
ko.applyBindingsToNode(element, { value: data[property] });
}
}
ko.applyBindings(viewModel);