Note that there are some explanatory texts on larger screens.

plurals
  1. POKnockout ajax foreach loop not working
    text
    copied!<p>I am trying to bind a array of data to my knockout template, but when I do try to bind it I get </p> <pre><code> Uncaught ReferenceError: Unable to parse bindings. Bindings value: foreach: attributes Message: attributes is not defined </code></pre> <p>Below is the ajax call I will use in order to get my data back. I have replaced the self.attributes with the expected data to be returned just to make it testable in jsfiddle.</p> <pre><code>$.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); } </code></pre> <p>here is my HTML</p> <pre><code>&lt;div class="itemAttributesContainer topBorder"&gt; &lt;h4&gt;Attributes&lt;/h4&gt; &lt;table id="attributeTable" data-bind="foreach: attributes"&gt; &lt;tr&gt; &lt;td&gt; &lt;span class="attrQuestion" data-bind="text: AttributeText + ': '" /&gt; &lt;span data-bind="text: Value" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p><a href="http://jsfiddle.net/2Tp4E/" rel="nofollow">http://jsfiddle.net/2Tp4E/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload