テーブルを動的に作成し、それをテーブルに解析しています。テーブルが表示されたら、ユーザーがすべての行をライブ検索できるようにしたいと思います。これを正しく機能させるのに問題があります。
ソースが含まれています - 次のコード セクションにスキップして、特にテーブル行のライブ検索に関連する 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>
ここで何が欠けていますか?コンテンツが動的に生成されているため、この方法を使用できませんか?
ありがとう