Note that there are some explanatory texts on larger screens.

plurals
  1. POKnockout.js foreach with MS WebAPI
    primarykey
    data
    text
    <p>defining two FOREACHs in two different DIVs as follow</p> <pre><code>&lt;div style="background-color:black; color:white; overflow:scroll; height:350px;width:300px"&gt; &lt;ol data-bind="foreach: price_quantity"&gt; &lt;li data-bind="text: quantity + ' &amp;&amp;&amp; ' + price"&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;div style="background-color:black; color:white; overflow:scroll; height:350px;width:300px"&gt; &lt;ul data-bind="foreach: papers" style="list-style-type:none"&gt; &lt;li&gt; &lt;div data-bind="text: paperName"&gt;&lt;/div&gt; &lt;ul data-bind="foreach : _colors" &gt; &lt;li&gt; &lt;div data-bind="style:{'background-color' : colorName}" style="height:25px;width:25px;border:1px solid white"&gt;&lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>and on $(document).ready, I am making two AJAX calls as below to populate two divs above with LIST</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function () { var sku = "abcd"; $.ajax({ url: "/api/values?clientSKU=" + sku, dataType: "json", asyc: true, type: "get", success: function (msg) { var skuandprice = $.parseJSON(msg); ko.applyBindings(new ViewPriceObjectOnWeb(skuandprice)); }, error: function (jqXHR, textStatus, errorThrown) { alert(textStatus + ' ' + errorThrown); } }); var appid= "123"; $.ajax({ url: "/api/Default1?app_id=" + appid, dataType: "json", asyc: false, type: "get", success: function (msg) { var paperandcolors = $.parseJSON(msg); ko.applyBindings(new PaperModal(paperandcolors)); }, error: function (jqXHR, textStatus, errorThrown) { alert(textStatus + ' ' + errorThrown); } }); </code></pre> <p>});</p> <pre><code>function ViewPriceObjectOnWeb(d) { this.price_quantity = ko.observableArray(d); } function PaperModal(paperArr) { this.papers = ko.observableArray(paperArr); } </code></pre> <p></p> <p>if I run them by commenting one or other DIV and not make corresponding call, it works fine. </p> <p>When Page Loads with both DIVS and their LISTS insided them, it gives error of</p> <p>Unable to parse bindings. Message: ReferenceError: 'price_quantity' is undefined; Bindings value: foreach: price_quantity</p> <p>Why this won't work? Any help is greately appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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