Jquery Masonry append item issues

与世无争的帅哥 提交于 2020-01-06 19:41:12

问题


I have a backbone fetch view method that does this:

var ResultsView = Backbone.View.extend({
  template : _.template($("#result_template").html()),
  render : function() {
    this.collection.each(function(result) {
      var $output = $(this.template(result.toJSON()));
      var $container = $('#result_content');
      $container.append($output)
      $container.masonry('appended', $output);
    }, this);
    return this;
  }
});

What I am trying to do is for every item in my results collection.... append it to my #result_content div, in the same fashion as can be seen here: http://masonry.desandro.com/demos/adding-items.html

The issue here is that the layout is not filled (it's just a single column at the moment. I have to call reload at the end of all of this like so:

$container.masonry('reload')

Which is not what I want. I want to append from top down.


回答1:


Change that line to $container.prepend($output).masonry('reload'); then remove the subsequent line $container.masonry('appended', $output); and also don't call "reload" at the end.



来源:https://stackoverflow.com/questions/12613416/jquery-masonry-append-item-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!