Page 1 of 1

autocomplete array push problem

Posted: Fri Feb 14, 2014 5:53 am
by pritu patel

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.??


autocomplete array push problem

Posted: Fri Feb 14, 2014 7:00 am
by Maryna Brodina

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


autocomplete array push problem

Posted: Fri Feb 14, 2014 9:17 am
by pritu patel

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.????


autocomplete array push problem

Posted: Fri Feb 14, 2014 4:27 pm
by Kateryna Grynko

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