Tim Tom
Tim Tom

Reputation: 2162

Why doesn't binding work in knockout in this case?

I have one of my ViewModels as:

Models.DayP = function (data) {
    var self = this;

    this.Mapping = {
        'Actions': {
            create: function (options) {
                return new App.Models.Action(self, options.data);
            }
        }
    };
}

and I have one of ViewModel as :

MPViewModel = function () {
      this.Model = {};
   this.Model.Test = ko.observable();

   //ajax request made below to set the data. Testis type of Models.DayP
}

and I have setup binding as:

<div data-bind="visible: Model.Test().Actions.length <= 0" style="display:none;"> </div>

Problem is this div always shows even though Model.Test().Actions is set after Ajax request, my div never hides itself.

Upvotes: 0

Views: 360

Answers (1)

Jason Goemaat
Jason Goemaat

Reputation: 29194

Try calling Actions as a function to get the underlying array:

<div data-bind="visible: Model.Test().Actions().length <= 0" style="display:none;"> </div>

Upvotes: 2

Related Questions