我正在尝试将一组数据绑定到我的淘汰赛模板,但是当我尝试绑定它时,我得到了
Uncaught ReferenceError: Unable to parse bindings.
Bindings value: foreach: attributes
Message: attributes is not defined
下面是我将用来取回数据的 ajax 调用。我已将 self.attributes 替换为要返回的预期数据,以使其在 jsfiddle 中可测试。
$.ajax({
url: '/api/MyApi',
type: 'GET',
dataType: 'json',
data: {
DamageId: urlCat
},
success:
function (data) {
ko.applyBindings(new DetailViewModel(currentDamage, fakeHistData, data));
},
error: function () {
}
});
function DetailViewModel(data, damHist,attrs) {
var self = this;
self.details = data;
self.attributes = '{[{"Id": 258,"Value": "Yes","AttributeId": 195,"AttributeName": "FurtherDamage","AttributeText": "Is the condition causing further damage to the property?"},{"Id": 259,"Value": "Zombie Attack","AttributeId": 196,"AttributeName": "Description","AttributeText": "Enter a description for the damage"}]}'
self.damHistory = ko.observableArray(damHist);
}
这是我的 HTML
<div class="itemAttributesContainer topBorder">
<h4>Attributes</h4>
<table id="attributeTable" data-bind="foreach: attributes">
<tr>
<td>
<span class="attrQuestion" data-bind="text: AttributeText + ': '" />
<span data-bind="text: Value" />
</td>
</tr>
</table>
</div>