2021年2月9日星期二

How to change value with another value of same object javascript

I have a JSON file

      [           { ""      : 1          , "id"    : 201610501          , "name"  : "MainMenu"          , "parent": null          }         ,           { ""      : 2          , "id"    : "201610501*"          , "name"  : "(*) Repeat"          , "parent": 201610501          }         ]   
and im fetching it like this  
    fetch('https://uccx116p.ef.com:8445/3rdpartygadget/files/JSON_files/Retailer_UC_1.json')              .then(res => res.json())              .then(data => {                  console.log(data)                            document.querySelector("#app").innerHTML = data.map(user => {                      return `<li id="list" onclick="openMessageBox(this)" ><a  href="#"> ${user.name}</a>         </li>                      `                                      })              })              .catch(() => console.log('cant'))          }      openMessageBox = function(el){              var name =el.textContent              console.log(name);  

On clicking the name I want to change it into its id how can I do that?

https://stackoverflow.com/questions/66130581/how-to-change-value-with-another-value-of-same-object-javascript February 10, 2021 at 11:38AM

没有评论:

发表评论