如何判断视图是否已经渲染? javascript
我正在使用backbone.js 创建我的应用程序
,如下所示,我有一个用于渲染布局的layoutView,以及布局中的一个迷你配置文件。
我遇到的问题是时间安排。在触发“renderProfile”方法之前,我需要先完成“render”方法。我怎样才能做到这一点?
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 complete 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())
@
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的情况就是我为 Backbone 编写 LayoutManager 的原因, http://github.com/tbranyen/backbone.layoutmanager。
您应该做的是将子视图与主(布局)视图分开。
因此,在您的路由回调中,您会看到类似这样的内容:
我恳请您研究我的库,因为我认为子视图与布局关联的声明方式确实非常优雅。
Your situation is why I wrote LayoutManager for Backbone, http://github.com/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:
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.