Created
July 10, 2014 16:32
-
-
Save DOOMer/b2250a729852b5b2c29f to your computer and use it in GitHub Desktop.
Fancy fields select append list options from JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% verbatim %} | |
<script type="text/javascript"> | |
$("#id_model_auto").fancyfields(); | |
$("#id_auto_vendor_select").fancyfields({ | |
onSelectChange: function (input,text,val){ | |
console.log("Current input - ID : "+input.attr("id") + " , selected text : " + text + " , value : " + val); | |
var url = "/classifieds/auto-liist/" + val + "/"; | |
$("#id_model_auto").fancyfields("clean"); | |
$.getJSON(url, | |
function(data){ // заполняем | |
var $models_list = $('#id_model_auto'); | |
$models_list.empty(); | |
$models_list.append( | |
$('<option>', {text: ''}) | |
) | |
var listOptions = [] | |
$.each(data['cars'], function(v, n){ | |
console.log(v); | |
console.log(n); | |
listOptions.push([n, v]); | |
//$models_list.append( | |
//$('<option>', {text: n, value: v}) | |
//); | |
}); | |
$("#id_model_auto").setOptions(listOptions); | |
}); | |
} | |
}); | |
</script> | |
{% endverbatim %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment