-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difficulty loading data via json call #171
Comments
The jQuery If you don't want to wait for me to support passing a jQuery Option 1: Make the ajax call before you call the Option 2: Call the |
Greg, |
I just released SelectBoxIt v3.6.0, which added deferred/promise object support to the // Calls the selectBoxIt method on your HTML select box
$("select").selectBoxIt({
defaultText: "Greg Franko Github Repos",
// Populates the drop down using a jQuery deferred object
populate: function() {
var deferred = $.Deferred(),
arr = [],
x = -1;
$.ajax({
url: 'https://api.github.com/users/gfranko/repos'
}).done(function(data) {
while(++x < data.length) {
arr.push(data[x].name);
}
deferred.resolve(arr);
});
return deferred;
}
}); |
Thanks! Sent via the Samsung Galaxy S™ II Skyrocket™, an AT&T 4G LTE smartphone.Greg Franko [email protected] wrote:I just released SelectBoxIt v3.6.0, which added deferred/promise object support to the populate() and add() methods. Here is an jQuery ajax example (I will soon have this example on the SelectBoxIt website): // Calls the selectBoxIt method on your HTML select box }); |
No problem! Also, you can see the example here: http://gregfranko.com/jquery.selectBoxIt.js/#jQueryDeferredObject |
I am able to initially populate the drop down menu in my SelectBoxIt from a JSON object useing "deferred.resolve(arr). But, when I try to update the drop down menu from another JSON object, the original options do not change. Do I need to ".refresh" at some point? I can remove the drop down menu items, but then I cannot populate them again. The only way I can change the drop down menu is remove the data options, and loop through the JSON object with a "listbox.add("option string'), one by one. My drop downs have over 1000 records, and this takes time. Please help. |
Greg,
I'm new to SelectBoxIt, but it looks great.
I am trying to load the box with remote data via a $ajax() call to my local server. I don't believe I have the call correct.
My code is as follows:
});
The call is returning the following structure which appears in the alert(d) display:
[
{ 'text': '0:', 'value': 'item_0' },
{ 'text': '1:', 'value': 'item_1' },
{ 'text': '2:', 'value': 'item_2' },
{ 'text': '3:', 'value': 'item_3' },
{ 'text': '4:', 'value': 'item_4' },
{ 'text': '5:', 'value': 'item_5' },
{ 'text': '6:', 'value': 'item_6' },
{ 'text': '7:', 'value': 'item_7' },
{ 'text': '8:', 'value': 'item_8' },
{ 'text': '9:', 'value': 'item_9' }
]
Any help or an examlpe of loading via a $ajax() call would be greatly appreciated. I need to be able to make dynamic loads of the options list throughout my code.
If I populate the json data manually everything works as expected.
thanks,
mike
The text was updated successfully, but these errors were encountered: