2013-06-25 83 views
0

我有一个JavaScript对象,我想用KnockoutJS与对象淘汰赛表绑定

这里绑定到一个表是我的对象:

var data = { 
    "Warnings": { 
    "numbers": 30, 
    "content": [ 
     { 
     "number" : 3001, 
     "description" : "There may be a problem with the device you are using if you use the default profile" 
     }, 
     { 
     "number" : 3002, 
     "description" : "There may be a problem with the device you are using if you don't use the default profile" 
     } 
    ] 
    }, 
    "Errors": { 
    "numbers": 20, 
    "content": [ 
     { 
     "number": 1000, 
     "description": "No network is loaded" 
     }, 
     { 
     "number": 1000, 
     "description": "No network is loaded" 
     } 
    ] 
    } 
}; 
ko.applyBindings(data); 

这里是我的html代码:

<table class="table table-hover"> 
    <thead> 
     <tr> 
      <th style="width:100px">Numero</th> 
      <th>Description</th> 
     </tr> 
    </thead> 
    <tbody data-bind="foreach: Warnings.content"> 
     <tr data-bind="foreach: $data"> 
      <td data-bind="text: $data.number"></td> 
      <td data-bind="text: $data.description"></td> 
     </tr> 
    </tbody> 
</table> 

这里是一个JSFiddle:http://jsfiddle.net/etiennenoel/KmKEB/

我真的需要使用这种格式为我的数据对象。

我不知道为什么我没有在表中列出,因为我没有得到任何错误的警告......

回答

2

您有没有需要额外的foreach。只需删除tr上的foreach即可。您的tbody上的foreach将为循环中呈现的每个tr分配$data的新值。

+0

这是[工作小提琴](http://jsfiddle.net/Tre2U/) –

+0

这是一个愚蠢的错误,谢谢! – CoachNono