How to determine if a view has been viewed? Javascript

I am building my application using backbone.js

As seen below, I have a layoutView that I use to render the layout as well as the mini profile in the layout.

I have a sync problem. I need to execute the render method first before running the renderProfile method. How can i do this?

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()) @ 
+4
source share
1 answer

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

What you should do is to split your approaches into the main (layout) representation.

So in your route callback you will 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 ask you to research my library, since I believe that the declarative manner in which submissions are related to layouts is really quite elegant.

+8
source

Source: https://habr.com/ru/post/1387494/


All Articles