chap3 -> Creating a binding to debug - the toJSON binding

chap3
Jason Zhu 2022-04-30 20:50:30 +10:00
parent f6a61ea524
commit be3a58c325
2 changed files with 9 additions and 0 deletions

View File

@ -19,6 +19,7 @@
</div> </div>
<div data-bind="template: {name:'add-to-catalog-modal'}"></div> <div data-bind="template: {name:'add-to-catalog-modal'}"></div>
<div data-bind="template: {name:'finish-order-modal'}"></div> <div data-bind="template: {name:'finish-order-modal'}"></div>
<pre class="well well-lg" data-bind="toJSON: $root"></pre>
</div> </div>
<!-- vendor library --> <!-- vendor library -->

View File

@ -23,3 +23,11 @@ ko.bindingHandlers.currency = {
}); });
}, },
}; };
ko.bindingHandlers.toJSON = {
update: function (element, valueAccessor) {
return ko.bindingHandlers.text.update(element, function () {
return ko.toJSON(valueAccessor(), null, 2);
});
},
};