Last active
December 19, 2015 11:38
-
-
Save danielmackay/5948776 to your computer and use it in GitHub Desktop.
Knockout dump binding handler.
This file contains 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
ko.bindingHandlers.dump = { | |
init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext){ | |
var context = valueAccessor(); | |
var allBindings = allBindingsAccessor)(); | |
var pre = document.createElement('pre'); | |
element.appendChild(pre); | |
var dumpJSON = ko.computed({ | |
read: function(){ | |
return ko.toJSON(context, null, 2); | |
}, | |
disposeWhenNodeIsRemoved: element | |
}); | |
// Lets you apply bindings programatically instead of declaritively | |
ko.applyBindingsToNode(pre, {text: dumpJSON}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment