Search code examples
javascriptarraysknockout.jsdata-bindingknockout-es5-plugin

Knockout binding handler pass array of objects


Is it possible to pass array value with square brackets for binding handler?, ie:

<div data-bind="validator: [{class: RequiredValidator}, {class: EmailValidator}]"></div>

It works fine for one object:

<div data-bind="validator: {class: RequiredValidator}"></div>

Class value is not observable, just javascript object.

It throws Message: Unexpected token ) error.

Or I need some other syntax? I could wrap it with object, but prefer not.

I took snapshot of project with this issue, available here: http://balin.maslosoft.com/array-validators/dev/validator.php

Open console, and object validators will show configuration, while array will fail.

Here is fiddle with minimal example: http://jsfiddle.net/piotr/fu8d0hm3/


Solution

  • It turned out that it was problem with knockout-es5 modification for two-way bindings.

    Original plugin is not affected. I've created pull request to address this issue.

    The problem was binding preprocessing, which produced invalid code if array value was passed.