What i'm trying to do is create an app that can be used offline. I have my data stored in a local json file and I would like to be able to filter that json data without it being hardcoded in a javascript file- these are only the examples I have seen for this.
This is a short example of my json file:
[
{
"ID": 1 ,
"name": "sub conjunctival haemorrhage",
"score" : 1,
"surgeryType": ["scleral buckle", "general", "ppv"]
},
{
"ID": 2,
"name": "dry eye",
"score": 5,
"surgeryType":["general", "pr"]
}
]
this filter below works but I don't know how to do it without hardcoding the data in the javascript file. How would I search by 'surgery type' but still keep the json in a json file instead of what is below?
<script>
var jsonText = '[
{
"ID":1,
"name":"sub conjunctival haemorrhage",
"score":1,
"surgeryType":["scleral buckle","general","ppv"]},
{
"ID":2,
"name":"dry eye",
"score":5,
"surgeryType":["scleral buckle","pr"]}]';
var jsonArray = JSON.parse(jsonText);
var surgerySearchTerm = "scleral buckle";
var filtered = jsonArray.filter(jsonObject =>
jsonObject.surgeryType.includes(surgerySearchTerm));
console.log("Filtered below");
console.log(filtered);
</script>