Note that there are some explanatory texts on larger screens.

plurals
  1. POAny way in JavaScript to avoid using setTimeout to execute a function right after another? Maybe with jQuery?
    primarykey
    data
    text
    <p>I'm using this code:</p> <pre><code>$newFilter = getNewFilter(); $fieldDropdown = getFieldDropdown(fieldData.field); $newFilter.append($fieldDropdown); $typeDropdown = getTypeDropdown($fieldDropdown.data('zenfilter').fieldId, $fieldDropdown.val(), fieldData.type); $newFilter.append($typeDropdown); $inputBox = getInputBox($typeDropdown.data('zenfilter').fieldId, $typeDropdown.data('zenfilter').fieldType, $typeDropdown.val(), fieldData.value); $newFilter.append($inputBox); </code></pre> <p>And I get a error (<code>$fieldDropdown.data("zenfilter") is null</code>) on the fourth line (<code>$typeDropdown = getTypeDropdown...</code>). This is because the <code>getFieldDropdown</code> didn't finished execution yet. How can I call the functions lineally? Thanks a lot.</p> <p>Edit: Added the getFieldDropdown function: </p> <pre><code>getFieldDropdown = function (populateData) { var $hiddenInput, i, $obj; $hiddenInput = $('&lt;input&gt;', { name: defaults.paramName + '[' + nFilters + '][field]', type: 'hidden' }); $obj = $('&lt;select&gt;&lt;/select&gt;', { 'class': classesHash.individualField, name: defaults.paramName + '[' + nFilters + '][fakefield]' }). data('zenfilter', { fieldId: nFilters }). addOption(fieldOptions). sortOptions(true). selectOptions(''). change(function(){ $(this).nextAll('select, div.' + classesHash.individualInputContainer).detach(); $(this).removeClass(classesHash.incompleteField).after(getTypeDropdown($(this).data('zenfilter').fieldId, $(this).val())); $(this).prev('input[type=hidden]').val(defaults.data[$(this).val()].fieldname); }); if (populateData) { for (i = 0; i &lt; defaults.data.length; i += 1) { if (defaults.data[i].fieldname === populateData) { $obj.selectOptions(String(i)); } } } return $hiddenInput.add($obj); }; </code></pre> <p>(addOptions, sortOptions and selectOptions are just a plugin's methods to manipulate selects easier, they don't do any AJAX)</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.
 

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