knockout.js - Durandal: Making a module of custom Knockout bindings -
I want to move all the custom bindings that I have made with the composition. I want to take EdbingHandler to a module , My main.js
method is clearer I have shown them in the file lib / binding / binding.js
, in the file needjs.config ()
Has an alias binding
created>, and calls require call with call ('binding') . However, the error in this code is not yet loaded for reference
app.start () call
app.start (). Then see the partial sequences in the 'Ideas' folder in the root // to view 'View' in the function () {// module ID. ViewLocator.useConvention (); Requirement ('binding' ); / / First: var structure = requires ('durnal / composition'); // first: composition.addBindingHandler () call which is now lib / binding / binding.js. $ .when (config.init () ). Function () {// Show the app by setting the root view model for our application with the transition. App.setRoot ('viewmodels / shell');})});
lib / binding / binding.js (probably does not make any difference, but is included for completion)
; (Define the work (define) ([['durandal / composition', 'knockout', 'datapikar'], function (composition, to, datapaker) [// The following announcement was originally originally after this announcement. : // Var composition = required ('durandal / composition'); // hidden: Inverse of 'View'. Composition.addBindingHandler ('hidden', {update: function (element, value assetor) {var value = ko. Utils.unwrapObservable (valueAccessor ()) to.banginghundlers.visional.update (element, function) (return! Value;});}}); // datepicker: again with date picker Composite form element. Composition.addBindingHandler ('datepicker', {init: function (element, value assetor) {var input = $ (" "); var span = $ (" & lt; span class = \ "input-group-adon \" & gt; & lt; i class = \ "Fa fa-cal endar \"> "); input.datepicker (); input.appendTo (element); span.appendTo (element) ;}});});}) (); I often wrap my binding in just an empty module which does not give anything like this -
Define ([], function () {// change any date with MM-DD-YYYY format. Js ko.bindingHandlers.Date = {update: function (Element, valueAccessor) {var value = valueAccessor (); var date = moment (value ()); var strDate = date.format ('MM / DD / YYYY'); $ (element) .text (strDate);} };});
Then it needs it in its shell.js module
Define (['Services / Binding'], Function (Binding) {}) ;
This is what you need to do in a nutshell. You are simply using the module to register custom bindings on the example of nodeouts.
Comments
Post a Comment