Last active
December 10, 2015 18:38
-
-
Save poonkave/4475971 to your computer and use it in GitHub Desktop.
Runtime injection of optios/optgroups to jQM select.
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
var deliveryJSON = { | |
"optGroups": [{ | |
"label": "FedEx", | |
"options": [{ | |
"value": "firstOvernight", | |
"label": "First Overnight" | |
}, { | |
"value": "expressSaver", | |
"label": "Express Saver" | |
}, { | |
"value": "ground", | |
"label": "Ground" | |
}] | |
}, { | |
"label": "UPS", | |
"options": [{ | |
"value": "firstOvernight", | |
"label": "First Overnight" | |
}, { | |
"value": "expressSaver", | |
"label": "Express Saver" | |
}, { | |
"value": "ground", | |
"label": "Ground" | |
}] | |
}, { | |
"label": "US Mail", | |
"options": [{ | |
"value": "standard", | |
"label": "Standard: 7 day" | |
}, { | |
"value": "rush", | |
"label": "Rush: 3 days" | |
}, { | |
"value": "express", | |
"label": "Express: next day" | |
}, { | |
"value": "overnight", | |
"label": "Overnight" | |
}] | |
}] | |
}; | |
var shippingJSON = { | |
"methods": [{ | |
"value": "standard", | |
"label": "Standard: 7 day" | |
}, { | |
"value": "rush", | |
"label": "Standard: 7 day" | |
}, { | |
"value": "express", | |
"label": "Express: next day" | |
}, { | |
"value": "overnight", | |
"label": "Overnight" | |
}] | |
}; | |
function fillShipping() { | |
var _options = [],i; | |
for (i = 0; i < shippingJSON.optGroups.length; i++) { | |
_options.push('<option value="' + shippingJSON.methods[i].value + '">' + shippingJSON.methods[i].label + '</option>'); | |
} | |
$('#shippingMethods').append(_options.join("")).selectmenu('refresh'); | |
} | |
function fillDelivery() { | |
var _options = [],i, j; | |
for (i = 0; i < deliveryJSON.optGroups.length; i++) { | |
_options.push('<optgroup label="' + deliveryJSON.optGroups[i].label + '">'); | |
for (j = 0; j < deliveryJSON.optGroups[i].options.length; j++) { | |
_options.push('<option value="' + deliveryJSON.optGroups[i].options[j].value + '">' + deliveryJSON.optGroups[i].options[j].label + '</option>'); | |
} | |
_options.push('</optgroup>'); | |
} | |
$('#deliveryMethods').append(_options.join("")).selectmenu('refresh'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment