user3194721
user3194721

Reputation: 815

knockout.js If condition is not working

I've tried below scenarios, but if condition is not working properly.

 <div data-bind="foreach: controlConfig" class="">
      <!-- ko if: $data.Title.toLowerCase() == $root.prodVersion.toLowerCase() -->

           <span data-bind="text: $data.Title" />
            <div data-bind="text: $root.prodVersion" />
        <!--/ko-->
</div>

    OR
     <div data-bind="foreach: controlConfig" class="">
      <!-- ko if: $data.Title == $root.prodVersion -->
     <span data-bind="text: $data.Title" />
            <div data-bind="text: $root.prodVersion" />
        <!--/ko-->
    </div>

    Any idea?

Upvotes: 1

Views: 917

Answers (1)

ebohlman
ebohlman

Reputation: 15003

If Title is an observable, you need to unwrap it if you're using it in an expression: $data.Title().toLowerCase() and $data.Title()==....

Upvotes: 3

Related Questions