I am trying to get data from json and push to array but it is not working. it is possible or not getting multiple object values from json. anybody can tell it is possible or not? if it is possible how we can do it and where i stucked from my code?
html
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
var searchVal = [];
var optionVal = [];
var autocompVal = [];
$.getJSON( "datas.json", function( data ) {
$.each( data, function( key, val ) {
searchVal.push( key.searchVal.searchname );
});
$.each( data, function( key, val ) {
optionVal.push( key.optionVal.optionname );
});
$.each( data, function( key, val ) {
autocompVal.push( key.autocompVal );
});
console.log("Show all Array value="+searchVal +"=="+ optionVal +"=="+autocompVal);
});
$("#autoComplete").autocomplete({
source: autocompVal,
select: function (event, ui) {//when we select something from the search box
this.value = ui.item.label;
alert(this.value);
return false;
}
});
});
</script>
<input type="text" id="autoComplete">
datas.json:
{
"searchVal": [
{ "searchname":"test1"},
{ "searchname":"test2"}
],
"optionVal": [
{ "optionname":"test11"},
{ "optionname":"test12"},
{ "optionname":"test13"}
],
"autocompVal": [
{ "test11"},
{ "test12"} ,
{ "test13"},
{ "test14"}
]
}