Reputation: 11
I am using durandal.js and i have to call some plguin on page load
this is what it would like in plain javascript
$('.testingShifter').shapeshift();
I just need to know is there any durandal(knockout) binding that i can use to call that javascript when page loads
Upvotes: 1
Views: 257
Reputation: 151
You can create an attached method in your viewmodel or you can create a custom binding for it.
e.g:
define(function () {
var vm = {
activate: activate,
attached: attached
}
var activate = function () {
//Do vm activation here
};
var attached = function(view) {
//do any dom stuff here.
var $testingShifter = $(view).find('.testingShifter');
$testingShifter.shapeshift();
};
return vm;
});
OR
ko.bindingHandlers.shapeShift= {
init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var allBindings = allBindingsAccessor();
var $testingShifter = $(element);
$testingShifter.shapeshift();
});
}
}
the custom binding handler would be called using:
data-bind="shapeshift:value"
on an html element.
Hope this helps.
Upvotes: 2