Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knockout BindingHandlers with no required values

Tags:

knockout.js

Is it possible to create a Knockout bindingHandler that has no required values?

ko.bindingHandlers['superAction'] = {
    init: function(...) { },
    update: function(...) { }
};

For example, the syntax might be:

<span data-bind="superAction"></span>

There is an optional value, so occasionally, it might be:

<span data-bind="superAction: myProperty"></span>

I've tried just a colon, no colon, .... They all cause run-time parsing exceptions.

like image 647
WiredPrairie Avatar asked Jan 27 '13 21:01

WiredPrairie


2 Answers

This is possible from knockout 3.0. See https://github.com/knockout/knockout/issues/289.

like image 69
Vukoje Avatar answered Oct 19 '22 17:10

Vukoje


No, everything inside the data-bind attribute should be a valid javascript object literal if wrapped in curly braces. And { superAction } is not.

like image 34
Angel Yordanov Avatar answered Oct 19 '22 16:10

Angel Yordanov