When fetching data from multiple JSON files with different number of data columns it returns undefined and breaks loop,

When fetching data from multiple JSON files with different number of data columns it returns undefined and breaks loop,

Content Index :

When fetching data from multiple JSON files with different number of data columns it returns undefined and breaks loop,
Tag : jquery , By : Frank
Date : November 29 2020, 09:01 AM

I think the issue was by ths following , You might need to do a bit of tweaking but this should get you very close:
   $.getJSON('data/lige.json', function (lige) {
  lige=lige.lige; // the file actually has an object whose first key is lige and we name the variable lige, to avoid confusion, normalize it here
  $.getJSON('data/ponude.json',function (ponude) {
    var tables=[];
    $.each(lige, function(li, le) {
      var lige_naziv = le.naziv; // string
      var lige_tipovi =le.razrade[0].tipovi; // array of objects, represents header values
      var lige_ponude=le.razrade[0].ponude; // array of int, represents row ids

      var title='<div class="head">'+lige_naziv+'</div>';

      var headers= li == 2 ? ['<th colspan="3"></th>'] : ['<th colspan="4"></th>']; // make long part of header
      var neededColumns=[]; // this part is key
      $.each(lige_tipovi, function(lti, lte) {  // lte =  [ {"naziv": "1" },...... ]
        neededColumns.push(lte.naziv); // track which ones we need for later

      var trs=[];
      $.each(lige_ponude, function(lpi, lpe) {  // lige_ponude =  [ 8991909, .... ]  ,  lpe =  8991909

        var found_ponude=false; // find the one with this id in the other json set, start out as false
        $.each(ponude, function(pi, pe) {  // pe = {  "broj":"12", "id":8991909, ....... }
            found_ponude=pe; // found it
            return false;
        if(found_ponude){ // make sure we found one
          var tds=['<td>'+found_ponude.broj+'</td><td>'+found_ponude.naziv+'</td>'];
          // now we loop over neededColumns NOT all of this group's values because there might be more on the group than on our table
          $.each(neededColumns, function(nci, nce) {  // neededColumns = [ 1, x, 2, ....]  , represents header columns that need to be filled in
            var found_ponude_tecajevi=false; // find the stored column value for this column, start out as false
            $.each(found_ponude.tecajevi, function(fpti, fpte) {  // tecajevi = [ { "tecaj":4.0,"naziv":"1"},... ]  , represents column values stored on object
              if(fpte.naziv==nce){ // found it
                found_ponude_tecajevi=fpte.tecaj || '-';
                return false;
              else found_ponude_tecajevi ='-'; //didnt find it
          tds.splice(1, 0, '<td>Time Here</td>');
          if(li==2){// we are on the second table and need to insert the signal icon as the 3rd column
            tds.splice(1, 0, '<td>Icon Here</td>');
          trs.push('<tr data-ponude-id="'+lpe+'">'+tds.join('')+'</tr>'); // create row
      tables.push(title+'<table><thead>'+headers+'</thead><tbody>'+trs.join('')+'</tbody> </table>'); // create table
    $('#data-output').html(tables.join('')); // add to page

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Jquery json multiple data returns undefined

Tag : php , By : Aires
Date : March 29 2020, 07:55 AM
wish helps you data is an object and you can access directly the a and b keys. If not, then you have to parse the JSON data using JSON.parse() method.
success: function(data) {
    data = JSON.parse(data);

Ember Data breaks when fetching JSON from Node + Express REST server

Tag : node.js , By : Brazen
Date : March 29 2020, 07:55 AM
will help you Looks like the mistake I made was in declaring model. ID attribute shouldn't be declared here, correct model looks like this:
App.Book = DS.Model.extend({
    author: DS.attr('string'),
    title: DS.attr('string')

How to fix fetching JSON data on inside of loop with limit number?

Tag : javascript , By : Juice
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , There is something bothers me. I'm trying to understand this output in console, take a look , Use this
listdata.orders.forEach(function (order) {
listdata.orders.slice(0, 9).forEach(function (order) {
listdata.orders.some(function (order, index) {
    if (index > 9) {
        return true;

Fetching data from local .json file in react.js returns multiple errors

Tag : json , By : 66.
Date : March 29 2020, 07:55 AM
will help you The question has been solved, The main issue was with defining const names such as const results = [] which should've been const results = props.results || [].
The code has been updated incase you have problems aswell.

Action Payload returns as undefined when fetching data in Redux

Tag : reactjs , By : Arun Thomas
Date : March 29 2020, 07:55 AM
will be helpful for those in need I am porting over a React application to use Redux. I can see that the action is firing on the click event, but when I add console.log to the action in the reducer, I'm seeing an undefined value. , I think that return statement is missing:
export const generateQuote = () => dispatch => {
  const randomNum = (Math.floor(Math.random() * (500 - 1)) + 1);
  return fetch(`https://jsonplaceholder.typicode.com/comments?id=${randomNum.toString()}`)
  .then(res => res.json())
  .then(data => 
      type: GENERATE_QUOTE, 
      payload: data[0],
      date: Date(Date.now())
 ).catch(error => console.log(error))
Related Posts Related QUESTIONS :
  • jQuery.load doesn't execute javascript with document.write
  • Animate hidden hyperlink to display:block
  • jquery ajax call returning error when its not an error
  • Exclude one or more elements from being connected (using connectWith) in jQuery's sortable lists
  • Adding link with existing href
  • jquery cycle plugin divs always stacked problem
  • jquery toggle and fade in one function?
  • JQuery UI Tabs caching
  • Drag and Drop into another div and move in the div only using jquery
  • Links in rounded boxes? In ALL browsers (yep included IE8)
  • How to change the content of the Span using jQuery?
  • jQuery; combine user click and :checked
  • jQuery - Finding the element index relative to its container
  • jQuery .each() function. Resetting the index?
  • jQuery storing settings
  • Why does asp.net mvc form submits itself on button clicks when javascript function error?
  • Linking to non-home panel in JQTouch site
  • How to Edit jQuery Table Using CSS
  • Jquery hover triggers "mouse leave" without cursor leaving
  • DELETE http://localhost:8000/product/[object%20Object] 500 (Internal Server Error)
  • Comparing two string arrays and returning key of not found element using jquery
  • using jquery to change list items is changing all list items, when i want to only change one list item
  • Sending a Json data from my html page to a php
  • Click function to search a specific element in a Json object
  • Bootstrap 4 - Progress Bar Progression
  • how to deleted item materialize chips
  • jQuery - Hide non-active elements using filter()
  • Adding style to string table is not working
  • Github merge multiple files into single compressed master file
  • Replace characters in a field on page load
  • Unable to send data from Form to SQL database
  • If all divs have same style, remove element
  • How to click a jQuery Dialog button in TestCafe
  • Cannot reinitialise DataTable with Angular Datatable
  • How to add Class active on Click in Navbar
  • how to call fail method into jquery.get/post success method?
  • Slider with tabs
  • Jquery Get parent element from data function
  • Ho to put a new line in <p> tag in my jquery?
  • How can I use a text value as a mathematical operator?
  • DataTable columns values showing Only DefaultContent
  • JQuery select dynamically added elements
  • How to change an image source on hover?
  • How to bind jquery event to dynamically added multiple DOM elements?
  • How to get td values and store in array using Jquery?
  • How to add handler to dinamically created tr in JQuery?
  • How to Covert Html to PDF in Jquery?
  • Jquery before() and after() used to create a <div> container not inserting closing tags in after()
  • I want to delete previously added class
  • Open html page in same window after clicking on navlink
  • Datatable is not working when I populate table using smarty
  • How to change image based on the offset top of the content div
  • Find the index of table column with specific id
  • How to return value of $(window).resize()
  • How to optimize adding numerous elements dynamically into web page
  • Content slide down on top of page?
  • How to write if statement for when a specified option is selected in select tag in JQuery
  • HTML tags remove from textarea using jQuery
  • ShareThis not display properly when initially hidden
  • jquery - Bind datepicker event
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com