knockout多个数组使用rowspan绑定到表

时间:2015-06-03 11:07:01

标签: javascript html knockout.js knockout-2.0

请参考此html,我使用knockoutjs生成报告。
请参阅**(1)和**(2)地点
如果我删除**(1)&保持**(2)位置tr这工作正常,但我的报告格式不能得到我所期望的。
如果我删除**(2)&保持**(1)我收到错误说"找不到匹配的评论标签:ko foreach:ProvinceArrayDTO"  但我需要的是拥有第二个选项并填充数组。

有没有办法实现这个目标?

在JSFiddle中Good Format STATIC DATA

Bad Format Dynamic from JSON



<table class="table table-striped table-bordered table-hover">
  <thead>
    <tr>
      <th>CEB Province</th>
      <th>CEB Area Office</th>
      <th>Primary Substation</th>
      <th>Meter</th>
      <th>Time Of Use</th>
      <th>Energy Initial Reading</th>
      <th>Energy Final Reading</th>
      <th>Total Energy in Time interval</th>
      <th>Total Energy</th>
      <th>Coincident Peak</th>
      <th>Remarks</th>
    </tr>
  </thead>
  <tbody>
    <!-- ko foreach: ProvinceArrayDTO -->
    <tr>
      <td data-bind="text: ProvinceName, attr: {rowspan: RowCount }"></td>
      <!-- ko foreach: AreaArrayDTO -->
      <td data-bind="text: AreaName, attr: {rowspan: RowCount }"></td>
      <!-- ko foreach: SubStationArrayDTO -->
      <td data-bind="text: SubStaionName, attr: {rowspan: RowCount }"></td>
      <!-- ko foreach: MetersArrayDTO -->
      <td data-bind="text: MeterName, attr: {rowspan: RowCount }"></td>
      <!-- ko foreach: MetersReadingArrayDTO -->
      <td class="auto-style5">Day</td>
      <td class="auto-style7">LastMnValue</td>
      <td class="auto-style2" data-bind="text: DayValue"></td>
      <td class="auto-style2">difference</td>


      <td class="auto-style4" rowspan="3">total</td>
      <td rowspan="3" data-bind="text: CoincidentPeak"></td>
      <td rowspan="3" data-bind="text: Remarks"></td>

    </tr>**(1)

    <td class="auto-style5">Peek</td>
    <td class="auto-style7">9804328</td>
    <td class="auto-style2">9523478</td>
    <td class="auto-style2">280,850</td>





    <!-- /ko -->
    <!-- /ko -->
    <!-- /ko -->
    <!-- /ko -->
    </tr>**(2)
    <!-- /ko -->


  </tbody>
</table>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

感谢您的观点!

我通过javascript生成了总表格布局并使用了淘汰赛的html绑定。

在淘汰赛中

&#13;
&#13;
self.DetailedReport = ko.observable();

function GenerateHtmlTableFronJson(){
  //JSON parse here ang generate HTML  
  return ("<table> ..... </table>");
  }

self.DetailedReport (GenerateHtmlTableFronJson());
&#13;
&#13;
&#13;

在HTML中

&#13;
&#13;
<div data-bind="html: DetailedReport"></div>
&#13;
&#13;
&#13;