jquery - How to determine if a view has been rendered? javascript - Stack Overflow

I am creating my application using backbone.jsAs seen below I have a layoutView which I use to render t

I am creating my application using backbone.js

As seen below I have a layoutView which I use to render the layout and also a mini profile within the layout.

The issue I have is with timing. I need to have the 'render' method plete first before triggering 'renderProfile' method. How can I do that?

Onethingaday.Views.Home ||= {}

class Onethingaday.Views.Home.LayoutView extends Backbone.View
  template: JST["backbone/templates/home/layout"]

  initialize: ->
    @options.user.bind('change',@render,@renderProfile, @)

  renderProfile: ->
    view = new Onethingaday.Views.Shared.MiniProfileView
      user: @options.user

    @$('.profile').html view.render().el

  render: ->
    $(@el).html(@template())
    @

I am creating my application using backbone.js

As seen below I have a layoutView which I use to render the layout and also a mini profile within the layout.

The issue I have is with timing. I need to have the 'render' method plete first before triggering 'renderProfile' method. How can I do that?

Onethingaday.Views.Home ||= {}

class Onethingaday.Views.Home.LayoutView extends Backbone.View
  template: JST["backbone/templates/home/layout"]

  initialize: ->
    @options.user.bind('change',@render,@renderProfile, @)

  renderProfile: ->
    view = new Onethingaday.Views.Shared.MiniProfileView
      user: @options.user

    @$('.profile').html view.render().el

  render: ->
    $(@el).html(@template())
    @
Share Improve this question asked Dec 22, 2011 at 2:48 ZhenZhen 12.4k38 gold badges125 silver badges200 bronze badges 2
  • Have you tried using $(document).ready(function(){ //after page loads }) ? – Control Freak Commented Dec 22, 2011 at 2:57
  • Did my solution not help you? – tbranyen Commented Dec 28, 2011 at 5:05
Add a ment  | 

1 Answer 1

Reset to default 8

Your situation is why I wrote LayoutManager for Backbone, http://github./tbranyen/backbone.layoutmanager.

What you should be doing is separating your sub views from your main (layout) view.

So in your route callback you'd have something like this:

// Initialize a Layout View
var profile = new Onethingaday.Views.Home.LayoutView();
// Initialize a MiniProfile View
var miniProfile = new Onethingaday.Views.Shared.MiniProfileView({
  model: user
});

// This appears synchronous in your code, so this should work fine
$(profile.render().el).find(".profile").html(miniProfile.render());

I would implore you to investigate my library, as I think the declarative manner in which sub views are associated to layouts is really quite elegant.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745087572a4610494.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信