When we are trying to parse a json object with foreach loop and a if condition to check the missing value , the following error will come below
<ul data-bind="foreach:foodMenu">
<li>Name <span data-bind="text:name"></span> , Type: <span data-bind="text:type"></span></li>
</ul>
<script>
var foodMenu = ko.observable([
{menuNo:"001",name:"Veg Biryani",price:100,type:"veg"},
{menuNo:"002",name:"Butter",price:50,type:"veg"},
{menuNo:"003",name:"Special Platter",price:600,type:"noveg"},
{menuNo:"004",name:"Fruit Juice",price:70}
])
When we try to execute the above code in the browser , the below message is coming
knockout-min.js:66 Uncaught ReferenceError: Unable to process binding "foreach: function(){return foodMenu }"
Message: Unable to process binding "text: function(){return type }"
Message: type is not defined
at text (eval at parseBindingsString (knockout-min.js:61), <anonymous>:3:57)
at update (knockout-min.js:91)
at function.a.j.q (knockout-min.js:66)
at l (knockout-min.js:44)
at Object.a.w.a.j (knockout-min.js:47)
at knockout-min.js:66
at Object.o (knockout-min.js:10)
at g (knockout-min.js:65)
at h (knockout-min.js:63)
at k (knockout-min.js:63)
To solve this error we need to update the code as below
<ul data-bind="foreach:foodMenu">
<li>Name <span data-bind="text:name"></span> , Type: <span data-bind="text:type"></span></li>
</ul>
<script>
var foodMenu = ko.observable([
{menuNo:"001",name:"Veg Biryani",price:100,type:"veg"},
{menuNo:"002",name:"Butter",price:50,type:"veg"},
{menuNo:"003",name:"Special Platter",price:600,type:"noveg"},
{menuNo:"004",name:"Fruit Juice",price:70,type:null}
])
This will fix the error
Checkout Julia Program
Where is Julia is used?
Julia can be used in the following list below
- Machine Learning
- Data Science
- Visualization
- General Purpose
- Parallel Computing
- Scientific Domains
Comments
Post a Comment