Answer the question
In order to leave comments, you need to log in
Why does autofill return [object object] data from an object?
I can't get the allfilms property from the object and add it to the autofill.
json overeats the object in this form, and I only need all the properties of the allfilms vow from it, add it to auto-fill. that is, it should output: sreck, rozdestvenskaya istoriya, rapuncel itd, but the object itself does not need to be changed, only the property is pulled out. Tell me who faced this how to do it?
$(function() {
var projects = [ {
"data": {
"allfilms": {
// нужны все эти свойства ток без ихних свойств , ток названия
"rosdestvenskaya istoriya": {},
"sreck": {},
"lednikoviy period": {},
"simsoni": {},
"sauth parck": {},
"rapuncel": {}
}
}
}
$( "#myinput" ).autocomplete({
minLength: 0,
source: projects,
focus: function( event, ui ) {
$( "#myinput" ).val( ui.item.data.allBrand);
return false;
},
select: function( event, ui ) {
$( "#myinput" ).val( ui.item.data.allBrand );
return false;
}
})
.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.data.allBrand + "<br>" + item.data.allBrand + "</a>" )
.appendTo( ul );
};
Answer the question
In order to leave comments, you need to log in
And why are you using such an inconvenient data structure?
1) You have an error in the structure declaration. There is no closing square bracket.
2) Even if the structure is valid, It will contain only one data object. And autocomplete takes an array of data. That is, you need to immediately slip an array into it.
3) Inside data you again have only one element allfilms. Roughly speaking, you need to slip the source for autocomplete like this - projects[0].data.allfilms. I don't guarantee it will work. Just a guess.
4) You access the source like this everywhere in the actocomplete -- item.data.allBrand. You don't have allBrand anywhere. Or I didn't understand something. I only see allfilms.
5) Each item or ul object in anonymous autocomplete methods has label and value properties. Here, if you do everything right, then in item.label, or in ul.label you should have the name of the movie.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question