Last active
October 1, 2015 16:22
-
-
Save EminenceHC/e85538de1f02923c1968 to your computer and use it in GitHub Desktop.
select options from array
This file contains hidden or 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
// I am using ajax to get an array of values which I want to turn into select options. | |
// When I log my array to console this is what I get: | |
Array[2], each item in the array looks like this: | |
Array[2] | |
0: "Abstain from substance abuse and participate in a recovery-based program." | |
1: 1 | |
1: Array[2] | |
0: "Engage in healthy, safe alternative activities to substance abuse that do not cause cognitive, behavioral, or emotional changes." | |
1: 5 | |
// Stringified the above array looks like this: | |
[["Abstain from substance abuse and participate in a recovery-based program.",1],["Accept the powerlessness and unmanageability over mood-altering substances and participate in a recovery-based program.",2],["Engage in healthy, safe alternative activities to substance abuse that do not cause cognitive, behavioral, or emotional changes.",5]] | |
// I am trying to figure out how I can take that array parse each item into an option, the last number in the array should be the actual option's value, and the text should be the label. | |
// I want to then be able to take that and update a select field like: | |
$('.my-select-field').empty().append(array-from-above); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment