我正在动态创建一个表并将其解析为一个表。显示表格后,我希望用户能够对所有行进行实时搜索。我在让它正常工作方面遇到问题。
包含的源代码 - 跳到下一个代码部分,查看与表行的实时搜索特别相关的 js。
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pairings</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js"></script>
<script src="http://www.parsecdn.com/js/parse-1.1.12.min.js"></script>
<script id="openDay" type="text/template">
<input type="text" id="search" placeholder="Type to search">
<table data-role="table" id="pairingsTable" data-mode="columntoggle" class="ui-responsive table-stroke">
<thead>
<th data-priority="2">Grp</th>
<th>Pro / Am</th>
<th data-priority="1">Thr</th>
<th data-priority="3">Fri</th>
<th data-priority="4">Sat</th>
</thead>
<tbody>
</script>
<script id="closeDay" type="text/template">
</tbody>
</table>
</script>
<script id="pairing" type="text/template">
<tr>
<td><%= this.model.get("GroupID") %></td>
<td style="padding:6px;"><%= this.model.get("Professional1") %> and <%= this.model.get("Amateur1") %><br>
<%= this.model.get("Professional2") %> and <%= this.model.get("Amateur2") %></td>
<td><%= this.model.get("ThursdayCourse") %><br>
<%= this.model.get("ThursdayTeeTime") %> <%= this.model.get("TenthTee1") %></td>
<td><%= this.model.get("FridayCourse") %><br>
<%= this.model.get("FridayTeeTime") %> <%= this.model.get("TenthTee2") %></td>
<td><%= this.model.get("SaturdayCourse") %><br>
<%= this.model.get("SaturdayTeeTime") %> <%= this.model.get("TenthTee3") %></td>
</tr>
</script>
<script>
$(function(){
Parse.$ = jQuery;
// Connect to Parse
Parse.initialize("soyC2zYsel97QtRsNhhNUxLoBgKe6kxnX0WxUBYT", "mZL82WFBjR2UUwJrwIu5WYLoRr0FzjPlHiTrD8zj");
var Pairing = Parse.Object.extend("golfTourney");
var Pairings = Parse.Collection.extend({
model: Pairing
});
var PairingView = Parse.View.extend({
template: _.template($("#pairing").html()),
initialize: function(){
_.bindAll(this, 'render');
},
render: function(){
return this.template(this.model);
}
});
var AppView = Parse.View.extend({
el: $("div"),
openTemplate: _.template($("#openDay").html()),
closeTemplate: _.template($("#closeDay").html()),
initialize: function() {
_.bindAll(this, 'render');
var self = this;
this.collection = new Pairings;
this.collection.query = new Parse.Query(Pairing);
this.collection.query.ascending("GroupID");
this.collection.fetch();
this.collection.bind('reset', function(){
self.render();
});
},
render: function(collection) {
var self = this, html = this.openTemplate();
console.log(this.collection);
this.collection.sortBy(function(m){
return m.get("GroupID");
})
this.collection.forEach(function(m){
var pairing = new PairingView({model: m});
html += pairing.render();
});
html += this.closeTemplate();
this.$el.append(html);
}
});
var appview = new AppView();
});
这是有问题的js....
$('#pairingsTable').load(function(){
var $rows = $('#pairingsTable tr');
$('#search').keyup(function() {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function() {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(val);
}).hide();
});
});
</script>
</head>
<body>
<div>
</div>
</body>
</html>
我在这里想念什么?由于我的内容是动态生成的,我不能使用这种方法吗?
谢谢