Absolutely love Durandal's architecture/clarity. But have ran into trouble getting durandal 2.0.1
to recognize any custom knockout binding.
My example View contains:
<div data-bind="test: {}" />
The binding is defined within an appBindings.js
that contains:
define([ 'jquery', 'knockout'],
function ($, ko) {
ko.bindingHandlers.test = {
init: function(element, valueAccessor, allBindingsAccessor) {alert(0);},
update: function(element, valueAccessor, allBindingsAccessor) {alert(1);}
}
var model = function(){}
return new model();
});
That is required
from main
:
requirejs.config({
paths: {
...
'durandal':'../lib/durandal/js',
'jquery': '../lib/jquery/jquery-1.9.1',
'knockout': '../lib/knockout/js/knockout-3.1.0',
'bootstrap': '../lib/bootstrap/js/bootstrap',
...
'bindings': 'bindings/appBindings'
},
shim: {
'bootstrap': ['jquery'],
//'ko-binding-test': ['jquery','knockout'],
}
});
define(['libs/core','durandal/system', 'durandal/app',
'durandal/viewLocator','services/resourceService','bindings'],
function (core, system, app, viewLocator, resourceService, bindings) {
//...
});
Observations:
- Chrome's traffic shows
appBindings.js
being loaded. - can breakpoint within
appBindings.js
as it gets loaded. - but no matter what I try,
init
/update
are never invoked. - the binding is functional outside of durandal (http://jsfiddle.net/skysigal/8LJw5/3/)
I've also tried various other ways of loading the binding definition:
- using in
main
adefine
+shim
of a non-AMD file containing the binding definition. - loading a non-AMD file (containing the binding definition) directly from index.html using a script tag
- making it a dependency of the
view
, notmain
.
Anyone have a suggestion as to the proper way to do this?
Thank you.