0

I need to use few binding properties in the same element and my syntax look fine for me, but VS said that ":" and "}" expected. What is wrong with my markup?

<div class="list-group" data-bind="foreach: histories, css: { bg-danger: $data.IsRead() == false}" id="histories">

2 Answers 2

3

The dash in your class requires you to use quotes, e.g.:

css: { 'bg-danger': $data.IsRead() == false}

See this fiddle.

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

Comments

2

You are essentially defining an object in your binding. It's as if you have written in regular javascript:

var css = {
    bg-danger: $data.IsRead() == false
}

Now you should know that hyphens are not legal in the name of an object literal, at least not written out like that. You have to quote it.

Change your binding to:

<div class="list-group" id="histories"
     data-bind="foreach: histories,
                css: { 'bg-danger': $data.IsRead() == false }">

p.s.,

$data.IsRead() == false

is better written out as

!$data.IsRead()

Comments

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.