pritu patel
Posts: 0
Joined: Tue Jan 21, 2014 6:24 am

autocomplete array push problem

I want to add another arrayitem using array.push()
But it's not working.
I am adding this code onsuucess event of autocomplete service.

arr = new Array();
$(data).each(function()
{ arr.push($(this)[0].SchemeName);
});
localStorage.setItem("mySuggestions", JSON.stringify(arr));
above code working perfectly..for 1 value retrive in array

arr = new Array();
$(data).each(function()
{ arr.push($(this)[0].SchemeName,$(this[1].id);
});
localStorage.setItem("mySuggestions", JSON.stringify(arr));

I used this code but not reflacting.What i want to do to get multiple value.??

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

autocomplete array push problem

Hello! Push should work, looks like you have a typo - missing right bracket prearr.push($(this)[0].SchemeName,$(this[1].id);/pre

pritu patel
Posts: 0
Joined: Tue Jan 21, 2014 6:24 am

autocomplete array push problem

thnks..it's my type error.
It's working on this code..
arr.push($(this)[0].SchemeName,$(this[0].id);

the out put like this:
["Sai Enclave","456","Sai Spring","495","Sai Crystal","2356","Sai Harmony","2360","Sai Fortune","2362","Sai Jewels","2364","Sai Miracle","2367","Sai Moksh","2372","Sai Pearls","2374","Sai Sapphire","2377"]

In autocomplete i want to pass id to call service.
But How i Got id from selected list name????
If i select sai Jewels in autocomplete then how to pass id for that item.????

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

autocomplete array push problem

Hi Pritu,

To output this ID use the following code:prevar offset = arr.indexOf("Sai Jewels");
if ((offset !== -1) && (arr.length offset + 1)){
alert("id=" + arr[offset + 1]);
}/pre

Return to “Issues”