Data-bind: {foreach: …} for multiple arrays

后端 未结 1 1559
我在风中等你
我在风中等你 2021-01-23 09:57

Is it possible to use data-bind: foreach for more than one array?
For example:

//do s
1条回答
  •  一生所求
    2021-01-23 10:43

    I don't think there is any official way of doing so, but a workaround would be, to use $index along with foreach on the longer array. Something like this:

    var model = function() {
      var self = this;
      
      self.arr1 = ko.observableArray([1,2,3, 5, 6]);
      self.arr2 = ko.observableArray([1,2,3,4]);
      
    }
    
    ko.applyBindings(new model());
    span {
      font-weight: bold;
    }
    
    
    Index: , Array 1: , Array 2: , Longer array: , Shorter array:

    0 讨论(0)
提交回复
热议问题