2014-03-12 21 views
1

我創建了一個JSFiddle,在這裏我的問題http://jsfiddle.net/benjishults/PMeJh/1/knockout.js在註釋中的foreach綁定不按預期方式工作

HTML:

<div data-bind="with: jobBeingViewed"> 
    <table> 
     <thead> 
      <tr> 
       <th data-bind="text: 'Days offset from ' + runtime"></th> 
       <th>-7</th> 
       <th>-6</th> 
       <th>-5</th> 
       <th>-4</th> 
       <th>-3</th> 
       <th>-2</th> 
       <th>-1</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
       <td data-bind="text: 'Actuals Availability'"></td> 
       <!-- ko.foreach: actuals --> 
       <td data-bind="text: $data"></td> 
       <!-- /ko --> 
      </tr> 
     </tbody> 
    </table> 
</div> 

的JavaScript:

function VM() { 
    function Job() { 
     this.runtime="2014-03-07"; 
     this.actuals = ko.observableArray([1,1,1,1,1,1,1]); 
    } 

    this.jobBeingViewed = ko.observable(new Job()); 

} 

ko.applyBindings(new VM()); 

在頁面上,第二排只有兩個填充柱,它看起來像這樣:

Actuals Availability  [object Object] 

我希望它看起來像這樣:

Actuals Availability  1  1  1  1  1  1  1 

我在做什麼錯?

我試過添加parens。我試過通過$ root.jobBeingViewed.actuals指向實際。都沒有工作。

回答

2

你錯就錯在ko.foreach

<!-- ko.foreach: actuals --> 

一個錯誤的點應該是

<!-- ko foreach: actuals --> 

工作例如:http://jsfiddle.net/PMeJh/2/

+0

謝謝!花了幾個小時試圖弄清楚這一點後,我實際上已經找到了答案,並在你出現時發佈自己的答案。你因速度而得分! – BPS

相關問題