Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@poonkave
Last active December 10, 2015 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poonkave/4475971 to your computer and use it in GitHub Desktop.
Save poonkave/4475971 to your computer and use it in GitHub Desktop.
Runtime injection of optios/optgroups to jQM select.
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