Bug Tracker

Ticket #7122: jquery-each-bug-wrong-link.html

File jquery-each-bug-wrong-link.html, 2.0 KB (added by liechtypo, 9 years ago)

jquery-each-bug-wrong-link

Line 
1<html>
2<head>
3  <script type="text/javascript" src="jquery-1.4.2.js"></script>
4  <script type="text/javascript">
5    $(function() {
6      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"}]};
7      var dataTable = $('#browse-table');
8      var thRow = $($(dataTable).find('tr')[0]).clone();
9      $('#browse-table tbody').empty();
10      drawCollections(data, dataTable, thRow);     
11    });
12
13    function drawCollections(newSet, dataTable, thRow) {
14      var table = dataTable;
15
16      $('#browse-table tbody').empty();
17      $('#browse-table').append(thRow);
18      var dataRow = $('<tr><td class="collection" scope="row"><a href="#"><span /></a></td><td class="records">0</td></tr>');
19      $.each(newSet.collections, function(index, value) {
20        dataRow.find('td.collection a span').text(value.title);
21        if (value.containsImages) {
22          dataRow.find('td.collection a img').show();
23        }
24        else {
25          dataRow.find('td.collection a img').hide();
26        }
27        dataRow.find('td.collection a').attr("href", value.uri);
28        dataRow.find('td.records').text(value.count);
29
30        table.append(dataRow);
31        dataRow = dataRow.clone();
32      });
33      $('#number_of_results').text(newSet.length);
34    }
35  </script>
36</head>
37<body>
38<table id="browse-table">
39  <tr>
40    <th class="th-collection">Title</th>
41    <th class="th-records">Records</th>
42  </tr>
43</table>
44</body>
45</html>