1

I'm using knockout with a foreach loop, and my specific element i want to bind the text element of a span to an anonymous function, however there is just a string version of the function returned <span data-bind="text: function(ri) { ri.itemNameAndRateplan() + ' ' + ri.Adults(); }"></span>

when run returns function (ri){ ri.itemNameAndRateplan() +' '+ ri.Adults();} as the html for the element. I would expect it to be something like ratePlanNameValue 4

How do i fix this?

1 Answer 1

2

You can actually just write data-bind="text: ri.itemNameAndRateplan() +' '+ ri.Adults()" If ri is an observable, add (). If this isn't the case I'd need to see some more code.

Sign up to request clarification or add additional context in comments.

2 Comments

This is an example, I want the result to be a bit more complex with more properties included than this, which is why I want to use the anonymous function. ri is an observable object
@mcgowan.b I would add a computed to the ri object, and just bind it. Writing extensive JS in a binding is just asking for problems. I've been down that road. I wouldn't recommend it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.