Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to use the following 'with' binding in knockout:

<td data-bind="with: $data.tiers()[$parents[1].Index]">
    ...
</td>

But I'm getting the error "Unexpected token );". If I just use $data.tiers()[0] it works, and I know that $parents[1].Index evaluates to a number. Is this just a limitation of knockout, that you can't use nested index accessors?

share|improve this question
    
Which KO version are you using? Can you try it with the latest 3.0 RC version knockoutjs.com/downloads/knockout-3.0.0rc.js? –  nemesv Oct 15 '13 at 13:59
    
I'm using 2.2.1. I just tried 3.0 RC, but it broke a whole host of other stuff, so I think I'll give that a miss. :P –  Tom Oct 15 '13 at 14:09
2  
Every day I see people here at SO that put alot of code in the View, it makes me sad because it defeats the purpose of MVVM –  Anders Oct 15 '13 at 14:29
    
Yeah, I am trying to minimise the code as much as I can, but it's quite a complex view, so it's quite hard to avoid. I'm fairly new to KO as well. –  Tom Oct 15 '13 at 14:42
2  
This is a known issue: ko.expressionRewriting.preProcessBindings failing at array expressions which should be fixed in version 3.0. You can find a possible workaround in the linked github issue. –  nemesv Oct 15 '13 at 14:52

1 Answer 1

This is a known issue: ko.expressionRewriting.preProcessBindings failing at array expressions which was be fixed in KO version 3.0.

If you cannot upgrade to 3.0 you can find a possible workaround in the linked github issue, so you just need to change your expression to:

<td data-bind="with: ($data.tiers()[$parents[1].Index])">
    ...
</td>

Demo JSFiddle.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.