2 Replies Latest reply on Sep 5, 2017 10:13 AM by mamyrand

    How to retrieve the content of navbar item that has been populated from AF Database

    mamyrand

      Hello, can someone help please?

      I have a project to produce the information found in PI System Explorer(database, system trees of elements, attributes...) and publish this into our Intranet.

      My approach is using the resource of PI Web API.

      When the user logged in, then she/he will receive the corresponding database information matching with her/his windows user identity.

      I can achieve up to now, displaying that database information on a bootstrap navigation bar.

      Now, I want to display the element(s) associated with each database every time the user click on each database.

      for that I have to get returned the Name of that database from a click event.

       

      below is what I did so far from my separate javascript file:

       

       

      ShowDatabases() {

       

      var username = $("#username").val();

       

      var password = $("#password").val();

       

      return $.ajax({

       

      'http://localhost:49499/pi/Databases?username='+username+'&password='+password+'',

       

      'GET',

       

      'application/json; charset=UTF-8',

       

      false,

       

      'json',

       

      function (data) {

       

      "#mydb").empty();

       

      for (i = 0; i < data.length; i++) {

       

      var src = $("#mydb");

       

       

      srcdata = "<li onclick=\"LoadElementList(event)\" id=\"" + data[i].Name + "\" ><a href=\"#\">" + data[i].Name + "</a></li>";

       

      src.append(srcdata);

       

       

       

       

       

       

       

      }

       

      function (xhr) {

       

       

      alert("Error: Please review your username and password.")

       

              },

       

          });

       

      }

       

       

       

      LoadElementList(event) {

       

      var x = event.target.id

      alert(x);

       

      }

       

      below is a portion of my html

       

      nav id="mynavbar" class="navbar navbar-inverse">

      <div class="container-fluid">

      <div class="navbar-header">

      <a class="navbar-brand" href="#">PI System Portal</a>

      </div>

      <div>

      <ul id="mydb" class="nav navbar-nav"></ul>

      </div>

      <div>

      <ul class="nav navbar-nav navbar-right">

      <li onclick="LoginForm()" id="login"><a href="#"><span class="glyphicon glyphicon-log-in" ></span> Login</a></li>

      <li onclick="LogOutForm()" id="logout"><a href="#"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>

      </ul>

      </div>

      </div>

      </nav>

       

      My question is how can I get returned the name of each item clicked on this navigation bar.

      having this will allow me to make a new request from pi web api to get the element list.

      in one word, the function LoadElementList(event) does not return the id that I expect to get.

      Thank you for your action.

      Mamy