javascript - Backbone.Marionette - append itemViews to different container depending on the height of containers -
javascript - Backbone.Marionette - append itemViews to different container depending on the height of containers -
what i'm trying achieve
i want render posts timeline. timeline consists of 2 columns append posts to. want able append post shorter column. new posts need prepended first column.
i have working code solves problem, sense it's not efficient be. marionette default attaches newly created elements documentfragment buffer, supposed speed rendering (less layout changes , such). need fetch posts after render timeline composite view (as both columns need attached dom have height).
this controller responsible showing view in part in app:
class app.controllers.companies extends marionette.controller initialize: -> @vent = _.extend {}, backbone.events show: -> posts = app.request "posts:collection" directoriespromise = app.request "directories:all" postsview = new app.views.posts.layout vent: @vent collection: posts postsview.on "render", -> posts.fetch() @_wait [directoriespromise], (directories) => app.execute "show:main", postsview please note i'm fetching posts after have rendered composite view, create sure collection empty , columns attached dom. otherwise there situations posts collection cached , fetched before view rendered, breaks getshortestcolumn (see below) function.
_wait wrapper jquery.wait function.
this part of timeline class, extends marionette.compositeview:
appendhtml: (compositeview, itemview, index) -> @getshortestcolumn().append itemview.el getshortestcolumn: -> minheight = number.max_value shortest = null @ui.columns.each -> if $(this).outerheight() < minheight shortest = $(this) minheight = $(this).outerheight() shortest the goal i want maintain current functionality leverage buffering available in marionette. want able fetch posts before show view (as directories), prevent timeouts or slow connection hindering user experience.
it seem not clear on i'm asking about, here's question: how accomplish that?
any suggestions or solutions welcome. thanksalot.
edit: forgot mention utilize marionette 1.8.6 , unfortunately can't update.
instead of doing fetch in render event (which called more might expect anyhow), can override show method, fetch there, , phone call base of operations show method after fetch done/failed.
or improve yet, have "controller" responsible fetching info , handing view rather view fetching itself.
javascript dom backbone.js coffeescript marionette
Comments
Post a Comment