18910140161

JavaScript-组合对象数组,然后为相关人员显示它们-堆栈溢出

顺晟科技

2022-10-19 13:03:56

249

我有许多对象要组合,然后只显示与另一个对象有匹配ID的对象。

例如;当用户单击John时,它将显示John进行的钓鱼旅行(在user Info对象和fishing Trip对象中有匹配的ID)。

https://plnkr.co/edit/m8x51cmtmmtnNF2s?open=lib%2fscript.js&deferrun=1


顺晟科技:

<!DOCTYPE html>

<html>
  <head>
    <link rel="stylesheet" href="lib/style.css" />
    <script src="lib/script.js"></script>
  </head>

  <body ng-app="plunker" ng-cloak>
    <div ng-controller="MainCtrl">
      <h1>Select relevant information from a list</h1><br>
      <table>
        <tr>
          <th>Name</th>
          <th>ID</th>
        </tr>
        <tr ng-repeat = "x in userInfo">
          <td>{{x.name}}</td>
          <td>{{x.ID}}</td>
          <td><button ng-click = "viewMore()">View More</button></td>
        </tr> 
      </table><br><br>
    <div ng-show = "showDiv">
      <table><h3>Selected Information</h3>
        <tr>
          <th>Name (Selection)</th>
          <th>Hobby (Selection)</th>
          <th>ID (Selection)</th>
        </tr>
        <tr ng-repeat = "x in userInfo">
          <td>{{x.name}}</td>
          <td>{{x.hobby}}</td>
          <td>{{x.ID}}</td>
        </tr> 
      </table><br><br>
      <div>
        <h3>Fishing Trips for selected person:</h3>
        {{fishingTrip1}} {{fishingTrip2}}
      </div>

    </div> 

      
    </div>
  </body>
</html>

和在您的js文件中

<!DOCTYPE html>

<html>
  <head>
    <link rel="stylesheet" href="lib/style.css" />
    <script src="lib/script.js"></script>
  </head>

  <body ng-app="plunker" ng-cloak>
    <div ng-controller="MainCtrl">
      <h1>Select relevant information from a list</h1><br>
      <table>
        <tr>
          <th>Name</th>
          <th>ID</th>
        </tr>
        <tr ng-repeat = "x in userInfo">
          <td>{{x.name}}</td>
          <td>{{x.ID}}</td>
          <td><button ng-click = "viewMore()">View More</button></td>
        </tr> 
      </table><br><br>
    <div ng-show = "showDiv">
      <table><h3>Selected Information</h3>
        <tr>
          <th>Name (Selection)</th>
          <th>Hobby (Selection)</th>
          <th>ID (Selection)</th>
        </tr>
        <tr ng-repeat = "x in userInfo">
          <td>{{x.name}}</td>
          <td>{{x.hobby}}</td>
          <td>{{x.ID}}</td>
        </tr> 
      </table><br><br>
      <div>
        <h3>Fishing Trips for selected person:</h3>
        {{fishingTrip1}} {{fishingTrip2}}
      </div>

    </div> 

      
    </div>
  </body>
</html>
  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航