spitzbuaamy
spitzbuaamy

Reputation: 771

Making Observable-Array Observable

I'm trying to show a different picture when it either is a favorite or not I'm getting the data from a data-base with breeze.js

<span class="projektZeile" data-bind="visible: isFavorite">
 <a href="" data-bind="click: function(data, event) { $parent.makeNoFavorite(projectName,data, event)}" ><img src="../../Content/Images/isFavorite.png"/></a>                           
</span>


  <span class="projektZeile" data-bind="visible: !isFavorite">     
        <a href="" data-bind="click: function(data, event) {$parent.makeFavorite(projectName,data, event)}" ><img src="../../Content/Images/makeFavorite.png"/></a>
      </span>

Here is the code where i fill the observable Array

self.favoriten.push({ projectName: item.Values[0].Name,
                            isFavorite: ko.observable(item.Values[0].IsFavorite())
                        });

Now my problem is, that if it is a favorite the right button is shown, but when it's not a favorite no picture is shown..

Upvotes: 0

Views: 93

Answers (2)

Paul Manzotti
Paul Manzotti

Reputation: 5147

Are you sure that the image is being served to the page correctly? Use Fiddler (or the network tab of developer tools) and check that the image is available to the browser, as the code looks fine to me.

Failing that, you can always use isFavorite() in your enable test to actually test the value, though I did think that Knockout should be able to cope with what you've put.

Upvotes: 2

Oliver Weichhold
Oliver Weichhold

Reputation: 10296

I would suspect a problem with your image path for non-favorites. To figure out what's going on use the developer tools of your favorite browser and observe the DOM.

Upvotes: 0

Related Questions