Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
¿Cómo hago un bucle a través de una matriz de 2 d para filtrar las matrices cuyos datos en la matriz coinciden con el valor deseado?

Esta es la matriz: Local esto: Datos del objeto: d: resultados: Matriz (3)

 0: {__metadata: {…}, Id: 1, Title: 'Item 1', staffInChargeId: 99, ID: 1} 1: {__metadata: {…}, Id: 15, Title: 'Item 2', staffInChargeId: 99, ID: 15} 2: {__metadata: {…}, Id: 16, Title: 'Item 3', staffInChargeId: 80, ID: 16}

¿Cómo puedo filtrar a través de la matriz para filtrar las matrices donde staffInChargeId es igual a LoginId?

 function LoadLinkResults(LoginId) { var LoginId = GetID(userIdLoginName); $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('userForm')/items?$select=ID,Title,staffInChargeId&?$top=20", headers: { Accept: "application/json;odata=verbose" }, async: false, success: function(data) { if (data.d.results.length > 0) { for (var i = 0; i < data.d.results.length; i++) { //how do I filter out the data whose staffInChargeId == LoginId? var item = data.d.results[i]; $('#LinkResults').append($("<option></option>").attr("value", item .staffInChargeId).attr("value", item .ID).text(item.Title)); } } }, error: function(data) { console.log("An error occurred. Please try again."); } }); } ```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Una sugerencia : su JSON contiene 2 propiedades de id en cada objeto. Idealmente debería haber uno ya que ambos contienen el mismo valor.

Ahora, si entiendo su requisito correctamente, puede usar Array.filter() para obtener los detalles del usuario que loggedIn . Aquí está la demostración :

 // Original Array const inputArr = [ {Id: 1, Title: 'Item 1', staffInChargeId: 99}, {Id: 15, Title: 'Item 2', staffInChargeId: 99}, {Id: 16, Title: 'Item 3', staffInChargeId: 80} ]; // Login Id const loginId = 80; // filterout the record based on the login Id. const filteredObject = inputArr.filter((obj) => obj.staffInChargeId === loginId); // Result console.log(filteredObject);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!