jQuery UI Autocomplete question on label and value
In the label we have item.ID + '-'+ item.Description
the va开发者_运维问答lue is item which is the object returned from the service.
When a selection is made 001-MyChoice
for ex. from the autocomplete, the value which is the datacontract object
is bound to the autocomplete field as [Object object]
. How can I get 001-MyChoice
to be bound for the selection ???
Pls help..
It's difficult to tell when you haven't posted any code to review. What format is your data returned from the service? JSON, XML?
I'm sure you're already looked at this link, but here it is just in case:
http://jqueryui.com/demos/autocomplete/#remote
Post some sample code of your js and some sample data of what your service returns for a better answer.
The autocomplete tags returned from your web service need to contain the tag 'term' and I think "ID", then the default call can help pull them out. Although not a perfect example if you look at the Jasonp example in the jQueryUI docs, that may help.
This is from memory but something like {"term":"dog", "ID": "123"}, {"term":"cat","ID": "2"}
So you have 001-MyChoice
as the label and you want it bound as the value?
Then don't specify the object returned
as the value. Label and value are not required by the autocomplete. You can specify both if you want one in the dropdown select (label
) and the other (value
) used as the value of the select.
If you want the select item and the value to be the same, then put the same item in either the label
or the value
property.
From the jquery autocomplete docs:
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.
If you need to use the datacontract object
, then just assign it to a variable in the select
callback function of the autocomplete and you can use it as that.
精彩评论