我正在尝试让 jPages 与 EmberJS 一起使用。jPages 似乎试图绑定到由于 Ajax 调用而无法及时加载的元素。有没有人让这个工作?这是 jsfiddle:http: //jsfiddle.net/stevenng/8hDRJ/33/
车把:
<div class="songs">
<script type="text/x-handlebars">
{{#view Songs.songsView}}
<div id="song-items">
{{#each Songs.songsController}}
<div class="song">
<p>{{artist}}</p>
</div>
{{/each}}
</div>
<div class="pagination"></div>
{{/view}}
</script>
</div>
JavaScript
Songs.songsController = Em.ArrayController.create({
content: [],
addSong: function(song) {
this.pushObject(song);
},
getSongs: function() {
var self = this;
$.ajax({
url: 'http://test.com/getSongs?callback=?',
dataType: "jsonp",
success: function(data){
var obj = $.parseJSON(data);
for (var i=0; i<obj.songs.length; i++) {
self.addSong( Songs.song.create( obj.songs[i]) );
}
}
});
}
});
Songs.songsView= Em.View.extend({
didInsertElement: function() {
$('.pagination').jPages({
containerID: "song-items",
perPage: 2
});
}
});