Tips for finding and showcasing content from a JSON file in an HTML format

A list of project names is being displayed in the side bar by retrieving them from a JSON result. When a user clicks on any of the listed project names on the side bar, it will show the details of that specific project. Additionally, there is now a search box to search for projects and display their details while also selecting the project name on the side bar.

Below is the code snippet for the search box:

<input class="form-control form-control-dark w-100" type="text" id="text" placeholder="Search" aria-label="Search">

The JSON result contains the following project information:

"projects": [
{
  "instances": null,
  "name": "decodingideas",
  "projectid": "decodingideas-147616",
  "projectnumber": 334691107943,
  "orgid": "",
  "orgname": "",
  "parentid": "",
  "parenttype": ""
},
 {
  "instances": null,
  "name": "pupil-workers",
  "projectid": "pupil-workers",
  "projectnumber": 455648594684,
  "orgid": "",
  "orgname": "",
  "parentid": "",
  "parenttype": ""
}

In this setup, searches can be performed based on project ID, name, or instance among other criteria.

Here's a glimpse of the HTML code used:

<div class="container-fluid">
  <div class="row">
    <nav class="col-md-2 d-none d-md-block bg-light sidebar">
      <div id="projectlist" class="sidebar-sticky">
        <ul class="nav flex-column nav-pills">

          {{range .Projects}}
          <li class="nav-item" >
            <a name="{{.ProjectID}}" class="nav-link" href="#">
              <img class="img-fluid" style="width:8%" src="static/image/generic_gcp.png">
              {{.Name}}
              <div>
                <small>
                  ProjectId: {{.ProjectID}}
                </small>
              </div>
            </a>
          </li>
          {{end}}

        </ul>

      </div>
    </nav>
    <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
      {{range .Projects}}
  
      <div id={{.ProjectID}} class="d-none justify-content-between flex-wrap 
        flex-md-nowrap align-items-center pb-2 mb-3 border-bottom ">
        <h1 class="h2">Project:{{.Name}}</h1>
      

This set up enables searching and displaying project details while also allowing users to select the desired project name from the side bar.

Answer №1

Check out this example using the auto complete feature from Jquery UI:

  $( function() {
 var projects= [
{
"instances": null,
"name": "codinggenius",
"projectid": "codinggenius-147616",
"projectnumber": 334691107943,
"orgid": "",
"orgname": "",
"parentid": "",
"parenttype": ""
},
 {
"instances": null,
"name": "coding-experts",
"projectid": "coding-experts",
"projectnumber": 455648594684,
"orgid": "",
"orgname": "",
"parentid": "",
"parenttype": ""
}
];
    $( "#projects" ).autocomplete({
      source: function (request, response) {
           response($.map(projects, function (value, key) {
                return {
                    label: value.name+" "+ value.projectid,
                    value: value.projectid
                }
            }));
        
    }, 
      select: function(event, ui) {
           var res= $('#projects').val(ui.item.projectid);
           }
    });
  } );
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.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>
 SEarch: <input id="projects">
If you prefer AJAX as the data source:

    var url="";//provide your URL for the JSON file
    source: function(request,response)  
    { 
      $.get(url, function(data)
      {         
        obj = JSON.parse(data);   //parse the data in JSON (if not already)
        response($.map(obj, function(value, key)
        {
         return {
                        label: value.name+" "+ value.projectid,
                        value: value.projectid
                    }
        }));
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The custom AJAX user control's JavaScript constructor is encountering an "element" that is undefined

I am attempting to develop a customized AJAX user control that includes a client-side object as well. Despite following the guidelines provided in this resource: https://msdn.microsoft.com/en-us/library/bb398906.aspx, I am encountering persistent issues. ...

Ways to eliminate the yellow highlighting on a row

In my current application, I am incorporating jqGrid and aiming to apply custom styling to it. To start, my objective is to eliminate the yellow highlighting effect that appears when clicking on a row in the jqGrid css. Despite my attempts, I have been u ...

Utilizing XSLT in ServiceMix

My current project involves writing an XSLT script to extract the content of a specific "content" div from an HTML page. I'm using Apache ServiceMix to create a service unit for this task, but I'm encountering some difficulties. At this point, m ...

Transitioning from Chrome's USB App API to the Web USB API

My current challenge involves migrating my API from a Chrome App to a Progressive Web Application due to the deprecation of the platform. I need to retain USB support in my web platform application, and someone recommended utilizing the Web USB API. Howev ...

Conceal the initial element featuring an image

Given that the post-body includes various elements, such as links and divs, I am interested in concealing only the first child element that contains an image. <div class="post-body"> <div class="separator"><img/></div> </div&g ...

What is the best way to display the original array when the search input for the title is left blank?

When I enter a todo item title in the search input field and then clear the search input, I expect the initial array of todos to be rendered again. I attempted to accomplish this using an if statement but it did not work - only the previously searched todo ...

Connect data dynamically to the p-table based on columns

I'm facing a challenge in displaying JSON data in a table format, and I'm looking for a way to accomplish this using p-table. When looping through the data, I'm noticing duplicate records in the rows. Can anyone guide me on how to achieve th ...

Utilizing GroupBy in RxJs for an Observable of Objects数组

I am working with entries of type Observable<Event[]>, and they are structured as follows: [{ "_id": 1, "_title": "Test Event 1", "_startDate": "2019-05-29T07:20:00.000Z", "_endDate": "2019-05-29T08:00:00.000Z", "_isAllDay": false }, ...

Upcoming construction: Issue encountered - The Babel loader in Next.js is unable to process .mjs or .cjs configuration files

Within my package.json file, I have set "type": "module" and "next": "^12.2.5". In my tsconfig.json: { "compilerOptions": { "target": "ES2022", "module": "esnext ...

Error: Express is undefined and does not have a property called 'use'

I'm encountering a problem with my express server specifically when I utilize the 'app.use' command. Within my task-routes.js file, the following code is present: import express from 'express'; const router = express.Router(); ...

Unable to pass the jQuery value - troubleshooting tips for Laravel

JavaScript Issue return response()->json([ 'category' => $category, 'editRoute' => $artistCategoriesEditRoute ]); AJAX Response category Object { id: 1, title: "tt", parent_id: 0, … } id ...

Tips for customizing font color on Google Maps Marker Clusterer

Is there a way to adjust the font color of a markerclusterer marker? Below is my current code for customizing the marker's style: mcOptions = {styles: [{ height: 27, url: "image.png", width: 35 ...

Make a diagonally slanted border for a cell

Is it feasible to create a table with diagonal borders using CSS or jQuery, similar to the one shown below? I would welcome any ideas on how this can be achieved. ...

Locate the midpoint index of the initial sequence occurrence within an array

I am trying to determine the midpoint of the first sequence that appears when given multiple strings in a large array For example: var array = ["c6dafc", "c6dafc", "1d2129", "1d2129", "1d2129", "cfcfff", "cfcfff", "ffffff", "1d2129", "1d2129", "1d2129", ...

Challenges with moving images in Unslider

There seems to be an issue with the unslider-arrows on the unslider banner. The images are not sliding properly when transitioning to the next image without user input. Instead, they resize from small to full size starting at the top of the .banner div. ...

The fusion of Combining Forms, JSON, AJAX, PHP, and Google graphs

I'm completely new to integrating JScript, Ajax, and Google Graphs. Although I've managed to get each of them working separately, combining them has proven to be quite challenging. Google Graph Part of my code (Form is inactive here): <html& ...

Using the ternary operator in PHP to output various statuses depending on an event's status in a SQL database

When the status is 1, it's referred to as an "Active Insurance Event," and when it's 2, it becomes a "Completed Insurance Event." if(!empty($ins_event)) { echo "<tr><td>&nbsp;<img src='/check-icon. ...

Inserting a picture using CSS

I attempted to include an image in a footer div, but I have not been successful with the following approach: Here is the HTML code I tried: <footer> <div class="imagenFooter" style="background-image: url(&quot;./images/footer-bg.jpg&quo ...

What is the best way to customize the color of the icon in the <v-text-field>?

I have a <v-toolbar> component and I am trying to customize it by adding a search text field with a search icon in front: <v-text-field ...