IT:AD:Durandal.JS:HowTo:Custom Bindings
Summary
Durandal is based on using MVVM.
MVVM is based on the View looking back at the ViewModel – not the Controller pushing (ie having knowledge of) to the View.
For that reason, use Bindings to load up data into a Control, rather than use the View's Activate method to use jquery to find the element in the view to load it.
Process
- Create an AMD module called 'appBindings.js' to hold your application's bindings (you'll probably end up with more than one).
- Reference it from the main.js.
- See:
Whereas the above is a IT:AD:Knockout.JS specific binding syntax, there is an alternate one: * http://www.ibrahimuludag.com/2013/08/knockout-custom-bindings-in-durandal.html
- Notice how the keyword difference (
addBindingHandler
is notko.bindingHandlers....
)
Resources
- Notice the different method name used in this technique: