Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery - function doesn't work on JSON imported data
    primarykey
    data
    text
    <p>I have an app that is importing data from JSON and generating (through JQuery's <code>append()</code>)a number of html lists representing the data:</p> <pre><code>&lt;ol id="iran"&gt; &lt;li class="y1900"&gt;&lt;p&gt;Iran 1900 Revolution flag&lt;/p&gt;&lt;/li&gt; &lt;li class="y1906"&gt;&lt;p&gt;Iran 1906 Dictator flag&lt;/p&gt;&lt;/li&gt; &lt;li class="y1921"&gt;&lt;p&gt;Iran 1921 Revolution flag&lt;/p&gt;&lt;/li&gt; &lt;/ol&gt; </code></pre> <p>I have a function <code>resizeFlags()</code> that (purely for UI) calculates the widths of each list item and resizes to fit everything into one screen.</p> <p>The <code>resizeFlags()</code> function is called during <code>$(document).ready()</code> (after the JSON load) and works fine with my test (static) html file, but does not work when the test html is removed and the same html is appended using the JSON data - the appended lists enter the DOM properly, but the resizing does not happen. </p> <p>I have a manual trigger for <code>resizeFlags()</code> (for recalculating based on a new year range) and that works as expected on the appended data.</p> <p>I feel like it's something obvious that I've overlooked - what am I missing?</p> <p>Edit:</p> <p>Here's the code that appends the data (I've temporarily moved <code>resizeFlags()</code> into this function, normally it's called straight after:</p> <pre><code>function loadFlags() { $.getJSON('data/flags.json',function(countriesdata){ //for each flag $.each(countriesdata.countries,function(i,countries){ $('#countries').append('&lt;li id="'+countries.country+'"&gt;'+countries.country+'&lt;/li&gt;') $('#flags').append('&lt;ol id="'+countries.country+'"&gt;&lt;/ol&gt;') $.each(countries.years,function(i,flagyears){ $('#flags #'+countries.country).append('&lt;li class="y'+flagyears.year+' '+flagyears.taxonomy+'"&gt;&lt;p&gt;'+flagyears.flagname+'&lt;/p&gt;&lt;/li&gt;') }); }); }); //resize from defaults resizeFlags(totalYears); } </code></pre>
    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.
 

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