Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:16:16+00:00 2026-06-14T22:16:16+00:00

defining two FOREACHs in two different DIVs as follow <div style=background-color:black; color:white; overflow:scroll; height:350px;width:300px>

  • 0

defining two FOREACHs in two different DIVs as follow

<div style="background-color:black; color:white; overflow:scroll; height:350px;width:300px">
<ol data-bind="foreach: price_quantity">
<li data-bind="text: quantity + ' &&& ' + price"></li>
</ol>
</div>
<div style="background-color:black; color:white; overflow:scroll; height:350px;width:300px">
<ul data-bind="foreach: papers" style="list-style-type:none">
<li>
<div data-bind="text: paperName"></div>
<ul data-bind="foreach : _colors" >
<li>
<div data-bind="style:{'background-color' : colorName}" style="height:25px;width:25px;border:1px solid white"></div>

</li>
</ul>
</li>
</ul>
</div>

and on $(document).ready, I am making two AJAX calls as below to populate two divs above with LIST

<script type="text/javascript">
$(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);
       }
   });

});

function ViewPriceObjectOnWeb(d) {
this.price_quantity = ko.observableArray(d);
}

function PaperModal(paperArr) {
this.papers = ko.observableArray(paperArr);
}

if I run them by commenting one or other DIV and not make corresponding call, it works fine.

When Page Loads with both DIVS and their LISTS insided them, it gives error of

Unable to parse bindings.
Message: ReferenceError: ‘price_quantity’ is undefined;
Bindings value: foreach: price_quantity

Why this won’t work? Any help is greately appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:16:17+00:00Added an answer on June 14, 2026 at 10:16 pm

    When you apply bindings more than once you need to specify which DOM element it will be referred to. In you case you need to do:

    ko.applyBindings(new ViewPriceObjectOnWeb(skuandprice), document.getElementById("divQuantity"));
    

    and the HTML is:

    <div id="divQuantity" style="background-color:black; color:white; overflow:scroll; height:350px;width:300px">
    <ol data-bind="foreach: price_quantity">
    

    The same with the second binding.

    But actually I would suggest to separate the binding from the updating the model. It means that you will call this binding code separately somewhere before any loading of data. And when you load data you only need to update the model:

    var ViewPriceObjectOnWeb = function()
    {
    var self = this;
    self.price_quantity = ko.observableArray(0);
    };
    ...
    var priceObject = new ViewPriceObjectOnWeb();
    ko.applyBindings(priceObject, document.getElementById("divQuantity"));
    ...
    $.ajax({
           url: "/api/values?clientSKU=" + sku,
           dataType: "json",
           asyc: true,
           type: "get",
           success: function (msg) {
                    priceObject.price_quantity = $.parseJSON(msg);          
           },
           error: function (jqXHR, textStatus, errorThrown) {
                   alert(textStatus + '  ' + errorThrown);
           }
       });
    

    The knockoutjs is so smart so it will update the DOM element as soon as model is updated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my system I have two different projects, one defining its interfaces and another
Currently, I have a Maven project which inherits from a parent pom defining two
Possible Duplicate: Two css files defining same class The answers to this question and
Given the following two ways of defining a class method in Ruby: class Foo
Reading some Verilog code, there seem to be two ways of defining arguments in
We have two installations of DB2. When defining a foreign key with a long
In a class inherited from dict, why don't the two ways of defining an
Is there a difference between defining a global operator that takes two references for
I'm defining a database for a customer/ order system where there are two highly
I have recently been thinking about the difference between the two ways of defining

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.