Skip to main content

Bug Tracker

Side navigation

Ticket #7122: jquery-each-bug-wrong-link.html
File jquery-each-bug-wrong-link.html, 2.0 KB (added by liechtypo, October 06, 2010 08:41PM UTC)

jquery-each-bug-wrong-link

<html>
<head>
  <script type="text/javascript" src="jquery-1.4.2.js"></script>
  <script type="text/javascript">
    $(function() {
      var data = {"collections":[{"collectionId":"1651961","title":"BBC","classification":"Census","region":"OTHER","uri":"http://www.bbc.co.uk","containsImages":true,"count":null},{"collectionId":"1783956","title":"MSNBC","classification":"Vital","region":"OTHER","uri":"http://www.msnbc.com","containsImages":false,"count":"609793"},{"collectionId":"1809046","title":"Fox News","classification":"Vital","region":"OTHER","uri":"http://www.foxnews.com","containsImages":false,"count":"6183"},{"collectionId":"1809045","title":"Yahoo News","classification":"Vital","region":"OTHER","uri":"http://news.yahoo.com","containsImages":false,"count":"31078"}]};
      var dataTable = $('#browse-table');
      var thRow = $($(dataTable).find('tr')[0]).clone();
      $('#browse-table tbody').empty();
      drawCollections(data, dataTable, thRow);      
    });

    function drawCollections(newSet, dataTable, thRow) {
      var table = dataTable;

      $('#browse-table tbody').empty();
      $('#browse-table').append(thRow);
      var dataRow = $('<tr><td class="collection" scope="row"><a href="#"><span /></a></td><td class="records">0</td></tr>');
      $.each(newSet.collections, function(index, value) {
        dataRow.find('td.collection a span').text(value.title);
        if (value.containsImages) {
          dataRow.find('td.collection a img').show();
        }
        else {
          dataRow.find('td.collection a img').hide();
        }
        dataRow.find('td.collection a').attr("href", value.uri);
        dataRow.find('td.records').text(value.count);

        table.append(dataRow);
        dataRow = dataRow.clone();
      });
      $('#number_of_results').text(newSet.length);
    }
  </script>
</head>
<body>
<table id="browse-table">
  <tr>
    <th class="th-collection">Title</th>
    <th class="th-records">Records</th>
  </tr>
</table>
</body>
</html>

Download in other formats:

Original Format