I have an autoplete field and have it's source set to an array of friends.
GetFollowing(9, function(response)
{
if (response)
{
donor.following = response;
for (var i = 0; i < response.length -1; i++)
{
// make sure we have an image to display
if (response[i].image != null)
{
$("#following").prepend("<li title='" + response[i].firstname + " " + response[i].lastname +
"'><img src='<?php echo $baseUrl;?>/uploads/profile-pictures/" + response[i].image +
"' alt='" + response[i].firstname + " " + response[i].lastname + "'/></li>");
// add to the friends array
if (! $.inArray(response[i].firstname + " " + response[i].lastname, friends))
friends.push(response[i].firstname + " " + response[i].lastname);
}
}
}
});
GetFollowers(9, function(response)
{
if (response)
{
donor.followers = response;
for (var i = 0; i < response.length -1; i++)
{
// make sure we have an image to display
if (response[i].image != null)
{
$("#followers").prepend("<li title='" + response[i].firstname + " " + response[i].lastname +
"'><img src='<?php echo $baseUrl;?>/uploads/profile-pictures/" + response[i].image +
"' alt='" + response[i].firstname + " " + response[i].lastname + "'/></li>");
// Add to the friends array
friends.push(response[i].firstname + " " + response[i].lastname);
}
}
}
// setup jquery-ui autoplete
$("#msg-to").autoplete({source: friends});
});
My problem is I need to associate an id with the value that is selected, how can this be done?
I have an autoplete field and have it's source set to an array of friends.
GetFollowing(9, function(response)
{
if (response)
{
donor.following = response;
for (var i = 0; i < response.length -1; i++)
{
// make sure we have an image to display
if (response[i].image != null)
{
$("#following").prepend("<li title='" + response[i].firstname + " " + response[i].lastname +
"'><img src='<?php echo $baseUrl;?>/uploads/profile-pictures/" + response[i].image +
"' alt='" + response[i].firstname + " " + response[i].lastname + "'/></li>");
// add to the friends array
if (! $.inArray(response[i].firstname + " " + response[i].lastname, friends))
friends.push(response[i].firstname + " " + response[i].lastname);
}
}
}
});
GetFollowers(9, function(response)
{
if (response)
{
donor.followers = response;
for (var i = 0; i < response.length -1; i++)
{
// make sure we have an image to display
if (response[i].image != null)
{
$("#followers").prepend("<li title='" + response[i].firstname + " " + response[i].lastname +
"'><img src='<?php echo $baseUrl;?>/uploads/profile-pictures/" + response[i].image +
"' alt='" + response[i].firstname + " " + response[i].lastname + "'/></li>");
// Add to the friends array
friends.push(response[i].firstname + " " + response[i].lastname);
}
}
}
// setup jquery-ui autoplete
$("#msg-to").autoplete({source: friends});
});
My problem is I need to associate an id with the value that is selected, how can this be done?
Share Improve this question asked Feb 27, 2012 at 23:25 Carl WeisCarl Weis 7,08215 gold badges65 silver badges86 bronze badges1 Answer
Reset to default 7http://jqueryui./demos/autoplete/
you should read the overview more.
Expected data format
The data from local data, a url or a callback can e in two variants:
- An Array of Strings:
[ "Choice1", "Choice2" ]
- An Array of Objects with label and value properties:
[ { label: "Choice1", value: "value1" }, ... ]
The label property is displayed in the suggestion menu. The value will be inserted into the input element after the user selected something from the menu. If just one property is specified, it will be used for both, eg. if you provide only value-properties, the value will also be used as the label.
use the label for textual representation, the value for the id per item in the selection.
you should also differentiate the textbox used for the visual version (which displays words) from the data version (a hidden input which contains id's) - similar to those of the datepicker widget (aka. alternate data). this can all be manipulated using the settings.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744116971a4559219.html
评论列表(0条)