JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://jquery-json.googlecode.com/files/jquery.json-2.2.min.js"></script>
<input type="text" id="scrivo" />
JavaScript
var data = {
json: $.toJSON({
"Re": [{
"nm": "Edward the Elder",
"cty": "GB",
"hse": "House of Wessex",
"yrs": "899-925"
}, {
"nm": "Edgar",
"cty": "GB",
"hse": "House of Wessex",
"yrs": "959-975"
}, {
"nm": "Edward the Martyr",
"cty": "GB",
"hse": "House of Wessex",
"yrs": "975-978"
}]
}),
delay: 0
}
var DEBUG = 0;
$('#scrivo').keyup(function () {
var jsonRe = (function () {
var json = null;
$.ajax({
async: false,
global: false,
url: "/echo/json/",
dataType: "json",
data: data,
type: "POST",
success: function (data) {
json = data;
}
});
return json.Re;
})();
if (DEBUG) console.log(jsonRe);
var value = $('#scrivo').val();
var o = $.grep(jsonRe, function (n) {
var contains = n.nm.indexOf(value) >= 0;
if (DEBUG) console.log(n.nm + ' ' + value + ' ' + contains);
return contains;
}, false);
console.log(o);
});