简体   繁体   中英

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.

尝试将Actions作为函数调用以获取底层数组:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM